summaryrefslogtreecommitdiff
path: root/tests/testutils.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-11-19 03:55:37 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-11-19 03:55:37 +0000
commit19ead4a5cb0dcefadb604c872e9f2b93430747f6 (patch)
tree36d2cb98f1fcf5dfa018aae577dd7060c887990d /tests/testutils.py
parent94348bfb78cc2576d586b5f1e6fde3e10c14b178 (diff)
downloadpsycopg2-19ead4a5cb0dcefadb604c872e9f2b93430747f6.tar.gz
Test cleanup.
Tests pass or fail gracefully on older PostgreSQL versions. If unittest2 is available, skip tests instead of printing warnings.
Diffstat (limited to 'tests/testutils.py')
-rw-r--r--tests/testutils.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/testutils.py b/tests/testutils.py
new file mode 100644
index 0000000..c047827
--- /dev/null
+++ b/tests/testutils.py
@@ -0,0 +1,46 @@
+# Utility module for psycopg2 testing.
+#
+# Copyright (C) 2010 Daniele Varrazzo <daniele.varrazzo@gmail.com>
+
+# Use unittest2 if available. Otherwise mock a skip facility with warnings.
+
+try:
+ import unittest2
+ unittest = unittest2
+except ImportError:
+ import unittest
+ unittest2 = None
+
+if hasattr(unittest, 'skipIf'):
+ from unittest2 import skip, skipIf
+
+else:
+ import warnings
+
+ def skipIf(cond, msg):
+ def skipIf_(f):
+ def skipIf__(self):
+ if cond:
+ warnings.warn(msg)
+ return
+ else:
+ return f(self)
+ return skipIf__
+ return skipIf_
+
+ def skip(msg):
+ return skipIf(True, msg)
+
+ def skipTest(self, msg):
+ warnings.warn(msg)
+ return
+
+ unittest.TestCase.skipTest = skipTest
+
+
+def decorate_all_tests(cls, decorator):
+ """Apply *decorator* to all the tests defined in the TestCase *cls*."""
+ for n in dir(cls):
+ if n.startswith('test'):
+ setattr(cls, n, decorator(getattr(cls, n)))
+