[Checkins] SVN: manuel/trunk/ fix https://bugs.launchpad.net/manuel/+bug/582482 by (more)

Benji York benji at zope.com
Thu May 20 23:07:14 EDT 2010


Log message for revision 112600:
  fix https://bugs.launchpad.net/manuel/+bug/582482 by (more)
  reworking the way test globs are handled
  

Changed:
  U   manuel/trunk/CHANGES.txt
  U   manuel/trunk/src/manuel/__init__.py
  U   manuel/trunk/src/manuel/bugs.txt
  U   manuel/trunk/src/manuel/doctest.py
  U   manuel/trunk/src/manuel/tests.py

-=-
Modified: manuel/trunk/CHANGES.txt
===================================================================
--- manuel/trunk/CHANGES.txt	2010-05-21 02:00:40 UTC (rev 112599)
+++ manuel/trunk/CHANGES.txt	2010-05-21 03:07:14 UTC (rev 112600)
@@ -1,11 +1,11 @@
 CHANGES
 =======
 
-1.1.1 (unreleased)
+1.1.1 (2010-05-20)
 ------------------
 
-- fix a bug that caused variables assigned in a doctest not to be reflected in
-  the passed-in globs dictionary; fixes half of launchpad bug 582482
+- fix the way globs are handled; fixes
+  https://bugs.launchpad.net/manuel/+bug/582482
 
 
 1.1.0 (2010-05-18)

Modified: manuel/trunk/src/manuel/__init__.py
===================================================================
--- manuel/trunk/src/manuel/__init__.py	2010-05-21 02:00:40 UTC (rev 112599)
+++ manuel/trunk/src/manuel/__init__.py	2010-05-21 03:07:14 UTC (rev 112600)
@@ -6,14 +6,6 @@
 EARLY = 'early'
 LATE = 'late'
 
-class GlobWrapper(dict):
-
-    def copy(self):
-        # XXX hack to trick doctest into making changes to the shared state
-        # instead of keeping a private copy
-        return self
-
-
 def timing(timing):
     assert timing in (EARLY, LATE)
     def decorate(func):
@@ -158,13 +150,10 @@
             parser(self)
 
     def evaluate_with(self, m, globs):
-        wrapped_globs = GlobWrapper(globs)
         for region in list(self):
             for evaluater in sort_handlers(m.evaluaters):
-                evaluater(region, self, wrapped_globs)
+                evaluater(region, self, globs)
 
-        globs.update(wrapped_globs)
-
     def format_with(self, m):
         for formatter in sort_handlers(m.formatters):
             formatter(self)

Modified: manuel/trunk/src/manuel/bugs.txt
===================================================================
--- manuel/trunk/src/manuel/bugs.txt	2010-05-21 02:00:40 UTC (rev 112599)
+++ manuel/trunk/src/manuel/bugs.txt	2010-05-21 03:07:14 UTC (rev 112600)
@@ -89,3 +89,63 @@
 
     >>> globs['b']
     2
+
+
+zope.testing.module
+-------------------
+
+At one point, because of the way manuel.doctest handles glob dictionaries,
+zope.testing.module didn't work.
+
+We need a globs dictionary.
+
+    >>> globs = {'foo': 1}
+
+To call the setUp and tearDown functions, we need to set up a fake test
+object that uses our globs dict from above.
+
+.. code-block:: python
+
+    class FakeTest(object):
+        def __init__(self):
+           self.globs = globs
+
+    test = FakeTest()
+
+
+Now we will use the globs as a module.
+
+    >>> import zope.testing.module
+    >>> zope.testing.module.setUp(test, 'fake')
+
+Now if we run this test through Manuel, the fake module machinery works.
+
+    The items put into the globs before the test are here.
+
+        >>> import fake
+        >>> fake.foo
+        1
+
+    And if we create new bindings, they appear in the module too.
+
+        >>> bar = 2
+        >>> fake.bar
+        2
+
+.. -> source
+
+.. code-block:: python
+
+    import manuel.doctest
+    m = manuel.doctest.Manuel()
+    document = manuel.Document(source)
+    document.process_with(m, globs=globs)
+
+The doctest in the `source` variable ran with no errors.
+
+    >>> print document.formatted()
+
+We should clean up now.
+
+    >>> import zope.testing.module
+    >>> zope.testing.module.tearDown(test)

Modified: manuel/trunk/src/manuel/doctest.py
===================================================================
--- manuel/trunk/src/manuel/doctest.py	2010-05-21 02:00:40 UTC (rev 112599)
+++ manuel/trunk/src/manuel/doctest.py	2010-05-21 03:07:14 UTC (rev 112600)
@@ -44,6 +44,14 @@
             assert region in document
 
 
+class DocTest(doctest.DocTest):
+    def __init__(self, examples, globs, name, filename, lineno, docstring):
+        # do everything like regular doctests, but don't make a copy of globs
+        doctest.DocTest.__init__(self, examples, globs, name, filename, lineno,
+            docstring)
+        self.globs = globs
+
+
 def evaluate(m, region, document, globs):
     # If the parsed object is not a doctest Example then we don't need to
     # handle it.
@@ -59,7 +67,7 @@
 
     runner.DIVIDER = '' # disable unwanted result formatting
     runner.run(
-        doctest.DocTest([region.parsed], globs, test_name,
+        DocTest([region.parsed], globs, test_name,
             document.location, region.lineno-1, None),
         out=result.write, clear_globs=False)
     region.evaluated = result

Modified: manuel/trunk/src/manuel/tests.py
===================================================================
--- manuel/trunk/src/manuel/tests.py	2010-05-21 02:00:40 UTC (rev 112599)
+++ manuel/trunk/src/manuel/tests.py	2010-05-21 03:07:14 UTC (rev 112600)
@@ -1,4 +1,3 @@
-from zope.testing import renormalizing
 import manuel
 import manuel.capture
 import manuel.codeblock



More information about the checkins mailing list