Commit fb2f9ce1 authored by Tres Seaver's avatar Tres Seaver

Clean out module-scope imports: .tests.test_savepoint

parent 69923979
...@@ -11,81 +11,56 @@ ...@@ -11,81 +11,56 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Tests of savepoint feature
"""
import unittest import unittest
import doctest
def testRollbackRollsbackDataManagersThatJoinedLater(): class SavepointTests(unittest.TestCase):
"""
def testRollbackRollsbackDataManagersThatJoinedLater(self):
A savepoint needs to not just rollback it's savepoints, but needs to # A savepoint needs to not just rollback it's savepoints, but needs
rollback savepoints for data managers that joined savepoints after the # to # rollback savepoints for data managers that joined savepoints
savepoint: # after the savepoint:
import transaction
>>> import transaction from transaction.tests import savepointsample
>>> from transaction.tests import savepointsample dm = savepointsample.SampleSavepointDataManager()
>>> dm = savepointsample.SampleSavepointDataManager() dm['name'] = 'bob'
>>> dm['name'] = 'bob' sp1 = transaction.savepoint()
>>> sp1 = transaction.savepoint() dm['job'] = 'geek'
>>> dm['job'] = 'geek' sp2 = transaction.savepoint()
>>> sp2 = transaction.savepoint() dm['salary'] = 'fun'
>>> dm['salary'] = 'fun' dm2 = savepointsample.SampleSavepointDataManager()
>>> dm2 = savepointsample.SampleSavepointDataManager() dm2['name'] = 'sally'
>>> dm2['name'] = 'sally'
self.assertTrue('name' in dm)
>>> 'name' in dm self.assertTrue('job' in dm)
True self.assertTrue('salary' in dm)
>>> 'job' in dm self.assertTrue('name' in dm2)
True
>>> 'salary' in dm sp1.rollback()
True
>>> 'name' in dm2 self.assertTrue('name' in dm)
True self.assertFalse('job' in dm)
self.assertFalse('salary' in dm)
>>> sp1.rollback() self.assertFalse('name' in dm2)
>>> 'name' in dm def test_commit_after_rollback_for_dm_that_joins_after_savepoint(self):
True # There was a problem handling data managers that joined after a
>>> 'job' in dm # savepoint. If the savepoint was rolled back and then changes
False # made, the dm would end up being joined twice, leading to extra
>>> 'salary' in dm # tpc calls and pain.
False import transaction
>>> 'name' in dm2 from transaction.tests import savepointsample
False sp = transaction.savepoint()
dm = savepointsample.SampleSavepointDataManager()
""" dm['name'] = 'bob'
sp.rollback()
def test_commit_after_rollback_for_dm_that_joins_after_savepoint(): dm['name'] = 'Bob'
""" transaction.commit()
self.assertEqual(dm['name'], 'Bob')
There was a problem handling data managers that joined after a
savepoint. If the savepoint was rolled back and then changes made,
the dm would end up being joined twice, leading to extra tpc calls and pain.
>>> import transaction
>>> sp = transaction.savepoint()
>>> from transaction.tests import savepointsample
>>> dm = savepointsample.SampleSavepointDataManager()
>>> dm['name'] = 'bob'
>>> sp.rollback()
>>> dm['name'] = 'Bob'
>>> transaction.commit()
>>> dm['name']
'Bob'
"""
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
doctest.DocTestSuite(), unittest.makeSuite(SavepointTests),
)) ))
# additional_tests is for setuptools "setup.py test" support
additional_tests = test_suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment