summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2008-05-05 12:31:40 +0200
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2008-05-05 12:31:40 +0200
commit7bff3da39a4ca51e0f4d890c7295d097a7496025 (patch)
tree81af5d41e63523bc45cd5effc711880c91c26324
parent1735784d51123aa2a8ddcab3139347510b92469a (diff)
downloadlogilab-common-7bff3da39a4ca51e0f4d890c7295d097a7496025.tar.gz
use pysqlite2 as the first choice rather than sqlite3
-rw-r--r--db.py2
-rw-r--r--test/unittest_testlib.py28
-rw-r--r--testlib.py17
3 files changed, 43 insertions, 4 deletions
diff --git a/db.py b/db.py
index d6b2bd8..c4e3498 100644
--- a/db.py
+++ b/db.py
@@ -540,7 +540,7 @@ class _MySqlDBAdapter(DBAPIAdapter):
PREFERED_DRIVERS = {
"postgres" : [ 'psycopg2', 'psycopg', 'pgdb', 'pyPgSQL.PgSQL', ],
"mysql" : [ 'MySQLdb', ], # 'pyMySQL.MySQL, ],
- "sqlite" : ['sqlite3', 'pysqlite2.dbapi2', 'sqlite', ],
+ "sqlite" : ['pysqlite2.dbapi2', 'sqlite', 'sqlite3',],
}
_ADAPTERS = {
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py
index d53c239..f969532 100644
--- a/test/unittest_testlib.py
+++ b/test/unittest_testlib.py
@@ -388,8 +388,34 @@ class TestLoaderTC(TestCase):
]
for pattern, expected_count in data:
yield self.assertRunCount, pattern, MyMod, expected_count
+
+ def test_pattern_and_variable_conflict(self):
+ class MyMod:
+ today = staticmethod(lambda: None)
+ class MyTestCase(TestCase):
+ def test_today(self): pass
+ data = [('today', 1)]
+ for pattern, expected_count in data:
+ yield self.assertRunCount, pattern, MyMod, expected_count
-
+
+ def test_testsuite_handling(self):
+ class MyMod:
+ class MyTestCase(TestCase):
+ def test_x(self): pass
+ def test_y(self): pass
+ def test_z(self): pass
+ def suite():
+ suite = TestSuite()
+ suite.addTest(MyMod.MyTestCase('test_x'))
+ suite.addTest(MyMod.MyTestCase('test_y'))
+ return suite
+ suite = staticmethod(suite) # make it easily callable
+ data = [('MyTestCase.test_y', 1)]
+ data = [('suite', 2)]
+ for pattern, expected_count in data:
+ yield self.assertRunCount, pattern, MyMod, expected_count
+
def test_collect_everything_and_skipped_patterns(self):
testdata = [ (['foo1'], 3), (['foo'], 2),
(['foo', 'bar'], 0),
diff --git a/testlib.py b/testlib.py
index ca3e62d..d873305 100644
--- a/testlib.py
+++ b/testlib.py
@@ -501,6 +501,18 @@ class starargs(tuple):
return tuple.__new__(cls, args)
+def is_testsuite(obj):
+ """convenience function which tests if `obj` is a TestSuite factory
+ """
+ if callable(obj):
+ try:
+ test = obj()
+ if isinstance(test, unittest.TestSuite):
+ return True
+ except TypeError:
+ return False
+ return False
+
class NonStrictTestLoader(unittest.TestLoader):
"""
@@ -562,7 +574,7 @@ class NonStrictTestLoader(unittest.TestLoader):
# python2.3 does not implement __iter__ on suites, we need to return
# _tests explicitly
return suite._tests
-
+
def loadTestsFromName(self, name, module=None):
parts = name.split('.')
if module is None or len(parts) > 2:
@@ -574,7 +586,8 @@ class NonStrictTestLoader(unittest.TestLoader):
collected = []
if len(parts) == 1:
pattern = parts[0]
- if callable(getattr(module, pattern, None)) and pattern not in tests:
+ obj = getattr(module, pattern, None)
+ if is_testsuite(obj) and pattern not in tests:
# consider it as a suite
return self.loadTestsFromSuite(module, pattern)
if pattern in tests: