[Zope-Checkins] CVS: Zope3/lib/python/Persistence/tests - testModule.py:1.6
Jeremy Hylton
jeremy@zope.com
Mon, 24 Jun 2002 15:18:36 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv31645/tests
Modified Files:
testModule.py
Log Message:
Try to cope with function that have module-level side-effects.
=== Zope3/lib/python/Persistence/tests/testModule.py 1.5 => 1.6 ===
from Persistence import tests
-# snippet of source code used by testModules
+# snippets of source code used by testModules
foo_src = """x = 1
def f(y):
return x + y
@@ -16,6 +16,12 @@
def f(y):
return x + y
"""
+side_effect_src = """x = 1
+def inc():
+ global x
+ x += 1
+ return x
+"""
class TestModule(unittest.TestCase):
@@ -85,17 +91,27 @@
self.assertEqual(bar.foo.f(4), 46)
self.assertEqual(foo.f(4), 46)
-## def testFunctionAttrs(self):
-## self.importer.module_from_source("foo", foo_src)
-## import foo
-## A = foo.f.attr = "attr"
-## self.assertEqual(foo.f.attr, A)
-## get_transaction().commit()
-## self.assertEqual(foo.f.attr, A)
-## foo.f._p_deactivate()
-## self.assertEqual(foo.f.attr, A)
-
-
+ def testFunctionAttrs(self):
+ self.importer.module_from_source("foo", foo_src)
+ import foo
+ A = foo.f.attr = "attr"
+ self.assertEqual(foo.f.attr, A)
+ get_transaction().commit()
+ self.assertEqual(foo.f.attr, A)
+ foo.f._p_deactivate()
+ self.assertEqual(foo.f.attr, A)
+ del foo.f.attr
+ self.assertRaises(AttributeError, getattr, foo.f, "attr")
+ foo.f.func_code
+
+ def testFunctionSideEffects(self):
+ self.importer.module_from_source("effect", side_effect_src)
+ import effect
+ effect.inc()
+ get_transaction().commit()
+ effect.inc()
+ self.assert_(effect._p_changed)
+
def test_suite():
return unittest.makeSuite(TestModule)