[Checkins] SVN: zope.sqlalchemy/trunk/ Setup sqlalchemy mappers in test setup and clear them in tear down. This
Brian Sutherland
jinty at web.de
Thu May 28 20:36:14 EDT 2009
Log message for revision 100525:
Setup sqlalchemy mappers in test setup and clear them in tear down. This
makes the tests more robust and clears up the global state after. It
caused the tests to fail when other tests in the same run called
clear_mappers.
Changed:
U zope.sqlalchemy/trunk/CHANGES.txt
U zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py
-=-
Modified: zope.sqlalchemy/trunk/CHANGES.txt
===================================================================
--- zope.sqlalchemy/trunk/CHANGES.txt 2009-05-28 21:26:18 UTC (rev 100524)
+++ zope.sqlalchemy/trunk/CHANGES.txt 2009-05-29 00:36:13 UTC (rev 100525)
@@ -7,6 +7,10 @@
* Pull in pysqlite explicitly as a test dependency.
* Add a global session factory registry so that applications can get the
Session from zope.sqlalchemy.
+* Setup sqlalchemy mappers in test setup and clear them in tear down. This
+ makes the tests more robust and clears up the global state after. It
+ caused the tests to fail when other tests in the same run called
+ clear_mappers.
0.4 (2009-01-20)
----------------
Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py 2009-05-28 21:26:18 UTC (rev 100524)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/tests.py 2009-05-29 00:36:13 UTC (rev 100525)
@@ -95,13 +95,6 @@
sa.ForeignKeyConstraint(('user_id',), ('test_users.id',)),
)
-orm.mapper(User, test_users,
- properties = {
- 'skills': orm.relation(Skill,
- primaryjoin=test_users.columns['id']==test_skills.columns['user_id']),
- })
-orm.mapper(Skill, test_skills)
-
bound_metadata1 = sa.MetaData(engine)
bound_metadata2 = sa.MetaData(engine2)
@@ -111,9 +104,18 @@
class TestOne(SimpleModel): pass
class TestTwo(SimpleModel): pass
-orm.mapper(TestOne, test_one)
-orm.mapper(TestTwo, test_two)
+def setup_mappers():
+ # Other tests can clear mappers by calling clear_mappers(),
+ # be more robust by setting up mappers in the test setup.
+ m1 = orm.mapper(User, test_users,
+ properties = {'skills': orm.relation(Skill,
+ primaryjoin=test_users.columns['id']==test_skills.columns['user_id']),
+ })
+ m2 = orm.mapper(Skill, test_skills)
+ m3 = orm.mapper(TestOne, test_one)
+ m4 = orm.mapper(TestTwo, test_two)
+ return [m1, m2, m3, m4]
class DummyException(Exception):
pass
@@ -163,12 +165,15 @@
class ZopeSQLAlchemyTests(unittest.TestCase):
def setUp(self):
+ self.mappers = setup_mappers()
metadata.drop_all(engine)
metadata.create_all(engine)
def tearDown(self):
transaction.abort()
metadata.drop_all(engine)
+ for m in self.mappers:
+ m.dispose()
def testAbortAfterCommit(self):
# This is a regression test which used to wedge the transaction
@@ -438,6 +443,7 @@
class MultipleEngineTests(unittest.TestCase):
def setUp(self):
+ self.mappers = setup_mappers()
bound_metadata1.drop_all()
bound_metadata1.create_all()
bound_metadata2.drop_all()
@@ -447,6 +453,8 @@
transaction.abort()
bound_metadata1.drop_all()
bound_metadata2.drop_all()
+ for m in self.mappers:
+ m.dispose()
def testTwoEngines(self):
session = UnboundSession()
More information about the Checkins
mailing list