[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/testing/setup.py
Added support for makeing doctest text files real modules
that can be
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Apr 1 11:07:54 EST 2005
Log message for revision 29782:
Added support for makeing doctest text files real modules that can be
accessed from ZCML and whose objects can be pickled.
Changed:
U Zope3/trunk/src/zope/app/testing/setup.py
-=-
Modified: Zope3/trunk/src/zope/app/testing/setup.py
===================================================================
--- Zope3/trunk/src/zope/app/testing/setup.py 2005-04-01 16:06:36 UTC (rev 29781)
+++ Zope3/trunk/src/zope/app/testing/setup.py 2005-04-01 16:07:53 UTC (rev 29782)
@@ -206,3 +206,43 @@
key = default.registrationManager.addRegistration(registration)
zapi.traverse(default.registrationManager, key).status = ActiveStatus
return default[folder_name]
+
+
+#------------------------------------------------------------------------
+# Setup of test text files as modules
+import sys
+
+# Evil hack to make pickling work with classes defined in doc tests
+class NoCopyDict(dict):
+ def copy(self):
+ return self
+
+class FakeModule:
+ """A fake module."""
+
+ def __init__(self, dict):
+ self.__dict = dict
+
+ def __getattr__(self, name):
+ try:
+ return self.__dict[name]
+ except KeyError:
+ raise AttributeError, name
+
+
+def setUpTestAsModule(test, name=None):
+ if name is None:
+ if test.globs.haskey('__name__'):
+ name = test.globs['__name__']
+ else:
+ name = test.globs.name
+
+ test.globs['__name__'] = name
+ test.globs = NoCopyDict(test.globs)
+ sys.modules[name] = FakeModule(test.globs)
+
+
+def tearDownTestAsModule(test):
+ del sys.modules[test.globs['__name__']]
+ test.globs.clear()
+
More information about the Zope3-Checkins
mailing list