From 2dab7d52f203ce76639bf2fb19e041d5f63f8008 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 26 Mar 2011 14:27:58 +0000 Subject: [PATCH] Fixed bytea encoding tests skipping when ctypes is not available --- tests/types_basic.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/types_basic.py b/tests/types_basic.py index 0eb6ac48..1ca668de 100755 --- a/tests/types_basic.py +++ b/tests/types_basic.py @@ -28,7 +28,7 @@ except: pass import sys import testutils -from testutils import unittest +from testutils import unittest, decorate_all_tests from testconfig import dsn import psycopg2 @@ -333,8 +333,8 @@ class ByteaParserTest(unittest.TestCase): try: self._cast = self._import_cast() except Exception, e: - return self.skipTest("can't test bytea parser: %s - %s" - % (e.__class__.__name__, e)) + self._cast = None + self._exc = e def _import_cast(self): """Use ctypes to access the C function. @@ -412,6 +412,18 @@ class ByteaParserTest(unittest.TestCase): 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(): return unittest.TestLoader().loadTestsFromName(__name__)