From: Mike Bayer Date: Sat, 29 Apr 2006 16:42:37 +0000 (+0000) Subject: added 'supports', 'unsupports' decorators to unittests so that they can all pass... X-Git-Tag: rel_0_1_7~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=deb80dbc7b1e0ec23c7eac6b1cd24799b1fb6b58;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added 'supports', 'unsupports' decorators to unittests so that they can all pass on all DBs --- diff --git a/test/defaults.py b/test/defaults.py index 096355826f..8d848f4c5e 100644 --- a/test/defaults.py +++ b/test/defaults.py @@ -131,7 +131,8 @@ class SequenceTest(PersistTest): ) cartitems.create() - + + @testbase.supported('postgres', 'oracle') def testsequence(self): cartitems.insert().execute(description='hi') cartitems.insert().execute(description='there') @@ -140,6 +141,7 @@ class SequenceTest(PersistTest): cartitems.select().execute().fetchall() + @testbase.supported('postgres', 'oracle') def teststandalone(self): s = Sequence("my_sequence", engine=db) s.create() @@ -149,6 +151,7 @@ class SequenceTest(PersistTest): finally: s.drop() + @testbase.supported('postgres', 'oracle') def teststandalone2(self): x = cartitems.c.cart_id.sequence.execute() self.assert_(1 <= x <= 4) diff --git a/test/inheritance.py b/test/inheritance.py index 9478441616..8b683b8ffb 100644 --- a/test/inheritance.py +++ b/test/inheritance.py @@ -384,7 +384,9 @@ class InheritTest5(testbase.AssertMixin): # shouldnt throw exception products = mapper(Product, product, inherits=contents) + def testbackref(self): + """this test is currently known to fail in the 0.1 series of SQLAlchemy, pending the resolution of [ticket:154]""" class ContentType(object): pass class Content(object): pass class Product(Content): pass diff --git a/test/objectstore.py b/test/objectstore.py index 4e61d08f0c..9ec6ca7e20 100644 --- a/test/objectstore.py +++ b/test/objectstore.py @@ -143,7 +143,8 @@ class SessionTest(AssertMixin): trans.commit() self.assert_(name_of(7) != name1, msg="user_name should not be %s" % name1) self.assert_(name_of(8) != name2, msg="user_name should not be %s" % name2) - + + @testbase.unsupported('sqlite') def test_true_nested(self): """tests creating a new Session inside a database transaction, in conjunction with an engine-level nested transaction, which uses @@ -185,7 +186,8 @@ class VersioningTest(AssertMixin): version_table.delete().execute() objectstore.clear() clear_mappers() - + + @testbase.unsupported('mysql') def testbasic(self): class Foo(object):pass assign_mapper(Foo, version_table, version_id_col=version_table.c.version_id) @@ -287,6 +289,8 @@ class PKTest(AssertMixin): def setUp(self): objectstore.clear() clear_mappers() + + @testbase.unsupported('sqlite') def testprimarykey(self): class Entry(object): pass diff --git a/test/selectresults.py b/test/selectresults.py index 6a3d9dd4d0..2e603580ac 100644 --- a/test/selectresults.py +++ b/test/selectresults.py @@ -42,8 +42,14 @@ class SelectResultsTest(PersistTest): assert self.res.count() == 100 assert self.res.filter(foo.c.bar<30).min(foo.c.bar) == 0 assert self.res.filter(foo.c.bar<30).max(foo.c.bar) == 29 + + @testbase.unsupported('mysql') + def test_aggregate_1(self): # this one fails in mysql as the result comes back as a string assert self.res.filter(foo.c.bar<30).sum(foo.c.bar) == 435 + + @testbase.unsupported('postgres', 'mysql') + def test_aggregate_2(self): # this one fails with postgres, the floating point comparison fails assert self.res.filter(foo.c.bar<30).avg(foo.c.bar) == 14.5 diff --git a/test/testbase.py b/test/testbase.py index 923ed7de99..8ef63ef278 100644 --- a/test/testbase.py +++ b/test/testbase.py @@ -59,13 +59,44 @@ def parse_argv(): db = engine.create_engine(db_uri, echo=echo, default_ordering=True, **opts) db = EngineAssert(db) +def unsupported(*dbs): + """a decorator that marks a test as unsupported by one or more database implementations""" + def decorate(func): + name = db.name + for d in dbs: + if d == name: + def lala(self): + echo_text("'" + func.__name__ + "' unsupported on DB implementation '" + name + "'") + lala.__name__ = func.__name__ + return lala + else: + return func + return decorate + +def supported(*dbs): + """a decorator that marks a test as supported by one or more database implementations""" + def decorate(func): + name = db.name + for d in dbs: + if d == name: + return func + else: + def lala(self): + echo_text("'" + func.__name__ + "' unsupported on DB implementation '" + name + "'") + lala.__name__ = func.__name__ + return lala + return decorate + +def echo_text(text): + print text + class PersistTest(unittest.TestCase): """persist base class, provides default setUpAll, tearDownAll and echo functionality""" def __init__(self, *args, **params): unittest.TestCase.__init__(self, *args, **params) def echo(self, text): if echo: - print text + echo_text(text) def setUpAll(self): pass def tearDownAll(self):