[Zope-Checkins] CVS: Zope3/lib/python/Persistence/tests - testModule.py:1.4
Jeremy Hylton
jeremy@zope.com
Fri, 21 Jun 2002 18:52:11 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv16428/tests
Modified Files:
testModule.py
Log Message:
Add a test of reactivation of module when function is called.
XXX Forgot to mention this in the previous checkin message for
Function. When a Function __call__()ed we must guarantee that it's
module is loaded so that the globals dict is valid.
=== Zope3/lib/python/Persistence/tests/testModule.py 1.3 => 1.4 ===
from ZODB.MappingStorage import DB
+from ZODB.utils import U64
from Persistence.Module import PersistentModuleImporter
from Persistence import tests
+# snippet of source code used by testModules
+foo_src = """x = 1
+def f(y):
+ return x + y
+"""
+quux_src = """from foo import x
+def f(y):
+ return x + y
+"""
+
class TestModule(unittest.TestCase):
def setUp(self):
@@ -40,6 +51,40 @@
self.assertEqual(pmtest.f(3), 4)
self.assertEqual(copy(3), 4)
+ def testModules(self):
+ self.importer.module_from_source("foo", foo_src)
+ # quux has a copy of foo.x
+ self.importer.module_from_source("quux", quux_src)
+ # bar has a reference to foo
+ self.importer.module_from_source("bar", "import foo")
+ # baz has reference to f and copy of x,
+ # remember the the global x in f is looked up in foo
+ self.importer.module_from_source("baz", "from foo import *")
+ import foo, bar, baz, quux
+ self.assert_(foo._p_oid is None)
+ get_transaction().commit()
+ self.assert_(foo._p_oid)
+ self.assert_(bar._p_oid)
+ self.assert_(baz._p_oid)
+ self.assert_(quux._p_oid)
+ self.assertEqual(foo.f(4), 5)
+ self.assertEqual(bar.foo.f(4), 5)
+ self.assertEqual(baz.f(4), 5)
+ self.assertEqual(quux.f(4), 5)
+ self.assert_(foo.f is bar.foo.f)
+ self.assert_(foo.f is baz.f)
+ foo.x = 42
+ self.assertEqual(quux.f(4), 5)
+ get_transaction().commit()
+ self.assertEqual(quux.f(4), 5)
+ foo._p_deactivate()
+ # foo is deactivated, which means its dict is empty when f()
+ # is activated, how do we guarantee that foo is also
+ # activated?
+ self.assertEqual(baz.f(4), 46)
+ self.assertEqual(bar.foo.f(4), 46)
+ self.assertEqual(foo.f(4), 46)
+
def test_suite():
return unittest.makeSuite(TestModule)