]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- rework the test suite to make use of SkipTest for tests skipped, unsupported, etc.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 22 Jan 2012 18:19:22 +0000 (13:19 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 22 Jan 2012 18:19:22 +0000 (13:19 -0500)
so that we can get an accurate picture what's really running/not, what's installed on jenkins, etc.
Tested in cpython 2.7 so far, we'll see what jenkins says about other platforms

test/bootstrap/noseplugin.py
test/lib/requires.py
test/lib/testing.py
test/orm/inheritance/test_magazine.py
test/orm/test_unitofwork.py

index 9cdfcee0e5f9ed672d51e82cd9b7005c2feb76a4..c9e85c8dc5ef65ffcfdceca7a2ebe175cd935375 100644 (file)
@@ -9,7 +9,7 @@ import StringIO
 
 import nose.case
 from nose.plugins import Plugin
-
+from nose import SkipTest
 from test.bootstrap import config
 
 from test.bootstrap.config import (
@@ -125,49 +125,54 @@ class NoseSQLAlchemy(Plugin):
         if not issubclass(cls, fixtures.TestBase):
             return False
         else:
-            if (hasattr(cls, '__whitelist__') and testing.db.name in cls.__whitelist__):
-                return True
+            if hasattr(cls, 'setup_class'):
+                existing_setup = cls.setup_class.im_func
             else:
-                return not self.__should_skip_for(cls)
+                existing_setup = None
+            @classmethod
+            def setup_class(cls):
+                self._do_skips(cls)
+                if existing_setup:
+                    existing_setup(cls)
+            cls.setup_class = setup_class
+
+            return True
 
-    def __should_skip_for(self, cls):
+    def _do_skips(self, cls):
         if hasattr(cls, '__requires__'):
             def test_suite(): return 'ok'
             test_suite.__name__ = cls.__name__
             for requirement in cls.__requires__:
                 check = getattr(requires, requirement)
-                if check(test_suite)() != 'ok':
-                    # The requirement will perform messaging.
-                    return True
+                check(test_suite)()
 
         if cls.__unsupported_on__:
             spec = testing.db_spec(*cls.__unsupported_on__)
             if spec(testing.db):
-                print "'%s' unsupported on DB implementation '%s'" % (
-                     cls.__class__.__name__, testing.db.name)
-                return True
+                raise SkipTest(
+                    "'%s' unsupported on DB implementation '%s'" % (
+                     cls.__name__, testing.db.name)
+                    )
 
         if getattr(cls, '__only_on__', None):
             spec = testing.db_spec(*util.to_list(cls.__only_on__))
             if not spec(testing.db):
-                print "'%s' unsupported on DB implementation '%s'" % (
-                     cls.__class__.__name__, testing.db.name)
-                return True
+                raise SkipTest(
+                    "'%s' unsupported on DB implementation '%s'" % (
+                     cls.__name__, testing.db.name)
+                    )
 
         if getattr(cls, '__skip_if__', False):
             for c in getattr(cls, '__skip_if__'):
                 if c():
-                    print "'%s' skipped by %s" % (
-                        cls.__class__.__name__, c.__name__)
-                    return True
-
-        for rule in getattr(cls, '__excluded_on__', ()):
-            if testing._is_excluded(*rule):
-                print "'%s' unsupported on DB %s version %s" % (
-                    cls.__class__.__name__, testing.db.name,
-                    _server_version())
-                return True
-        return False
+                    raise SkipTest("'%s' skipped by %s" % (
+                        cls.__name__, c.__name__)
+                    )
+
+        for db, op, spec in getattr(cls, '__excluded_on__', ()):
+            testing.exclude(db, op, spec, "'%s' unsupported on DB %s version %s" % (
+                    cls.__name__, testing.db.name,
+                    testing._server_version()))
 
     def beforeTest(self, test):
         testing.resetwarnings()
@@ -180,9 +185,3 @@ class NoseSQLAlchemy(Plugin):
         engines.testing_reaper._stop_test_ctx()
         if not config.options.low_connections:
             testing.global_cleanup_assertions()
-
-    #def handleError(self, test, err):
-        #pass
-
-    #def finalize(self, result=None):
-        #pass
index 65ad0aa8f5cf80d0eb2d8fa6734ad7ffd9671182..89b9a317b05a530d55a9c8328ff276a3ef1e31a6 100644 (file)
@@ -20,7 +20,7 @@ from test.lib import config
 import testing
 import sys
 
-def deferrable_constraints(fn):
+def deferrable_or_no_constraints(fn):
     """Target database must support derferable constraints."""
     return _chain_decorators_on(
         fn,
index 53a277b9df887437b8b3983fbeac0e22d80d2dc9..1d00d04d88929ce64c9ccf0abc1cdafd1c2f2092 100644 (file)
@@ -188,10 +188,7 @@ def _block_unconditionally(db, reason):
         if spec(config.db):
             msg = "'%s' unsupported on DB implementation '%s+%s': %s" % (
                 fn.__name__, config.db.name, config.db.driver, reason)
-            print msg
-            if carp:
-                print >> sys.stderr, msg
-            return True
+            raise SkipTest(msg)
         else:
             return fn(*args, **kw)
     return decorate
@@ -206,10 +203,7 @@ def only_on(dbs, reason):
         else:
             msg = "'%s' unsupported on DB implementation '%s+%s': %s" % (
                 fn.__name__, config.db.name, config.db.driver, reason)
-            print msg
-            if carp:
-                print >> sys.stderr, msg
-            return True
+            raise SkipTest(msg)
     return decorate
 
 def exclude(db, op, spec, reason):
@@ -231,10 +225,7 @@ def exclude(db, op, spec, reason):
         if _is_excluded(db, op, spec):
             msg = "'%s' unsupported on DB %s version '%s': %s" % (
                 fn.__name__, config.db.name, _server_version(), reason)
-            print msg
-            if carp:
-                print >> sys.stderr, msg
-            return True
+            raise SkipTest(msg)
         else:
             return fn(*args, **kw)
     return decorate
@@ -300,10 +291,7 @@ def skip_if(predicate, reason=None):
         if predicate():
             msg = "'%s' skipped on DB %s version '%s': %s" % (
                 fn.__name__, config.db.name, _server_version(), reason)
-            print msg
-            if carp:
-                print >> sys.stderr, msg
-            return True
+            raise SkipTest(msg)
         else:
             return fn(*args, **kw)
     return decorate
index 70387477f6e6d61dab4c53a5b6b9508b0ade522d..840270e589f9e375bef37ffaf95d615d863f02bc 100644 (file)
@@ -121,7 +121,7 @@ class MagazineTest(fixtures.MappedTest):
             Column('name', String(45), default=''),
         )
 
-def generate_round_trip_test(use_unions=False, use_joins=False):
+def _generate_round_trip_test(use_unions=False, use_joins=False):
     def test_roundtrip(self):
         publication_mapper = mapper(Publication, publication_table)
 
@@ -216,6 +216,6 @@ def generate_round_trip_test(use_unions=False, use_joins=False):
     setattr(MagazineTest, test_roundtrip.__name__, test_roundtrip)
 
 for (use_union, use_join) in [(True, False), (False, True), (False, False)]:
-    generate_round_trip_test(use_union, use_join)
+    _generate_round_trip_test(use_union, use_join)
 
 
index be781109d29b35c93b7ca7909b4acec52ece85bf..362ff35ca1f3ffceedb5ca7e7099e1b973a19703 100644 (file)
@@ -2359,12 +2359,7 @@ class InheritingRowSwitchTest(fixtures.MappedTest):
         )
 
 class TransactionTest(fixtures.MappedTest):
-    __requires__ = ('deferrable_constraints',)
-
-    __whitelist__ = ('sqlite',)
-    # sqlite doesn't have deferrable constraints, but it allows them to
-    # be specified.  it'll raise immediately post-INSERT, instead of at
-    # COMMIT. either way, this test should pass.
+    __requires__ = ('deferrable_or_no_constraints',)
 
     @classmethod
     def define_tables(cls, metadata):