Log message for revision 113651: actually test the ability to __getstate__
Changed: U Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py -=- Modified: Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py =================================================================== --- Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py 2010-06-19 15:04:13 UTC (rev 113650) +++ Zope/branches/gotcha-LP143531/src/OFS/tests/test_Uninstalled.py 2010-06-19 15:16:30 UTC (rev 113651) @@ -13,7 +13,14 @@ ############################################################################## import unittest +from OFS.SimpleItem import SimpleItem +from Testing.ZopeTestCase import base + +class ToBreak(SimpleItem): + pass + + class TestsOfBroken(unittest.TestCase): """Tests for the factory for "broken" classes. """ @@ -103,18 +110,45 @@ for meth_name in PERSISTENCE_METHODS: meth = getattr(inst, meth_name) # doesn't raise + +class TestsIntegratedBroken(base.TestCase): + def test_Broken_instance___getstate___gives_access_to_its_state(self): - from OFS.Uninstalled import Broken - OID = '\x01' * 8 - inst = Broken(self, OID, ('Products.MyProduct.MyClass', 'MyClass')) - inst.__setstate__({'x': 1}) - self.assertEqual(inst.__getstate__(), {'x': 1}) + from Acquisition import aq_base + from OFS.Uninstalled import BrokenClass + from OFS.tests import test_Uninstalled + import transaction + # store an instance + tr = ToBreak() + tr.id = 'tr' + self.app._setObject('tr', tr) + # commit to allow access in another connection + transaction.commit() + # remove class from namespace to ensure broken object + del test_Uninstalled.ToBreak + # get new connection that will give access to broken object + app = base.app() + inst = aq_base(app.tr) + self.failUnless(isinstance(inst, BrokenClass)) + state = inst.__getstate__() + self.assertEqual(state, {'id': 'tr'}) + + # cleanup + app.manage_delObjects('tr') + transaction.commit() + # check that object is not left over + app = base.app() + self.failIf('tr' in app.objectIds()) + + def test_suite(): suite = unittest.TestSuite() - suite.addTest( unittest.makeSuite(TestsOfBroken)) + suite.addTest(unittest.makeSuite(TestsOfBroken)) + suite.addTest(unittest.makeSuite(TestsIntegratedBroken)) return suite + def main(): unittest.main(defaultTest='test_suite') _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins