Fixed bytea encoding tests skipping when ctypes is not available

This commit is contained in:
Daniele Varrazzo 2011-03-26 14:27:58 +00:00
parent 7716cc6a0c
commit 2dab7d52f2

View File

@ -28,7 +28,7 @@ except:
pass pass
import sys import sys
import testutils import testutils
from testutils import unittest from testutils import unittest, decorate_all_tests
from testconfig import dsn from testconfig import dsn
import psycopg2 import psycopg2
@ -333,8 +333,8 @@ class ByteaParserTest(unittest.TestCase):
try: try:
self._cast = self._import_cast() self._cast = self._import_cast()
except Exception, e: except Exception, e:
return self.skipTest("can't test bytea parser: %s - %s" self._cast = None
% (e.__class__.__name__, e)) self._exc = e
def _import_cast(self): def _import_cast(self):
"""Use ctypes to access the C function. """Use ctypes to access the C function.
@ -412,6 +412,18 @@ class ByteaParserTest(unittest.TestCase):
self.assertEqual(rv, tgt) self.assertEqual(rv, tgt)
def skip_if_cant_cast(f):
def skip_if_cant_cast_(self, *args, **kwargs):
if self._cast is None:
return self.skipTest("can't test bytea parser: %s - %s"
% (self._exc.__class__.__name__, self._exc))
return f(self, *args, **kwargs)
return skip_if_cant_cast_
decorate_all_tests(ByteaParserTest, skip_if_cant_cast)
def test_suite(): def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__) return unittest.TestLoader().loadTestsFromName(__name__)