[Checkins] SVN: manuel/trunk/ fix a couple of bugs:

Benji York benji+zope.org at benjiyork.com
Tue Aug 17 20:08:03 EDT 2010


Log message for revision 115747:
  fix a couple of bugs:
  
  - Respect test runner reporting switches (e.g., zope.testrunner's --ndiff
    switch)
  - Fixed a bug that caused post-mortem debugging to not work most of the
    time.
  

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

-=-
Modified: manuel/trunk/CHANGES.txt
===================================================================
--- manuel/trunk/CHANGES.txt	2010-08-17 18:05:37 UTC (rev 115746)
+++ manuel/trunk/CHANGES.txt	2010-08-18 00:08:03 UTC (rev 115747)
@@ -1,14 +1,23 @@
 CHANGES
 =======
 
+1.3.0 (unreleased)
+------------------
+
+- Respect test runner reporting switches (e.g., zope.testrunner's --ndiff
+  switch)
+- Fixed a bug that caused post-mortem debugging to not work most of the
+  time.
+
+
 1.2.0 (2010-06-10)
 ------------------
 
 - Conform to repository policy.
-
 - Switch to using zope.testrunner instead of zope.testing due to API changes.
   zope.testing is now only required for testing.
 
+
 1.1.1 (2010-05-20)
 ------------------
 

Modified: manuel/trunk/src/index.txt
===================================================================
--- manuel/trunk/src/index.txt	2010-08-17 18:05:37 UTC (rev 115746)
+++ manuel/trunk/src/index.txt	2010-08-18 00:08:03 UTC (rev 115747)
@@ -303,6 +303,9 @@
 This uses the syntax implemented in :mod:`manuel.capture` to capture a block of
 text into a variable (the one named after "->").
 
+    >>> 1
+    2
+
 Whenever a line of the structure ".. -> VAR" is detected, the text of the
 *previous* block will be stored in the given variable.
 

Modified: manuel/trunk/src/manuel/__init__.py
===================================================================
--- manuel/trunk/src/manuel/__init__.py	2010-08-17 18:05:37 UTC (rev 115746)
+++ manuel/trunk/src/manuel/__init__.py	2010-08-18 00:08:03 UTC (rev 115747)
@@ -20,6 +20,7 @@
         module_path = module_path[:-1]
     return module_path
 
+
 def absolute_import(name):
     module_path = normalize_module_path(imp.find_module(name)[1])
 
@@ -315,6 +316,8 @@
 
 class Manuel(object):
 
+    _debug = False
+
     def __init__(self, parsers=None, evaluaters=None, formatters=None):
         if parsers is not None:
             self.parsers = parsers
@@ -331,6 +334,9 @@
         else:
             self.formatters = []
 
+        # other instances that this one has been extended with
+        self.others = []
+
     def add_parser(self, parser):
         self.parsers.append(parser)
 
@@ -341,10 +347,28 @@
         self.formatters.append(formatter)
 
     def __extend(self, other):
+        self.others.append(other)
+        self.debug = max(self.debug, other.debug)
         self.parsers.extend(other.parsers)
         self.evaluaters.extend(other.evaluaters)
         self.formatters.extend(other.formatters)
 
+    # the testing integration (manuel.testing) sets this flag when needed
+    @apply
+    def debug():
+        def getter(self):
+            debug = self._debug
+            if self.others:
+                debug = max(debug, max(m.debug for m in self.others))
+            return debug
+
+        def setter(self, value):
+            self._debug = value
+            for m in self.others:
+                m.debug = value
+
+        return property(getter, setter)
+
     def __add__(self, other):
         m = Manuel()
         m.__extend(self)

Modified: manuel/trunk/src/manuel/bugs.txt
===================================================================
--- manuel/trunk/src/manuel/bugs.txt	2010-08-17 18:05:37 UTC (rev 115746)
+++ manuel/trunk/src/manuel/bugs.txt	2010-08-18 00:08:03 UTC (rev 115747)
@@ -148,3 +148,37 @@
 
     >>> import zope.testing.module
     >>> zope.testing.module.tearDown(test)
+
+
+Debug flag and adding instances
+-------------------------------
+
+The unittest integration (manuel.testing) sets the debug attribute on Manuel
+objects.  Manuel instances that result from adding instances together need to
+have the debug value passed to each Manuel instances that was added together.
+
+    >>> m1 = manuel.Manuel()
+    >>> m2 = manuel.Manuel()
+
+The debug flag starts off false...
+
+    >>> m1.debug
+    False
+    >>> m2.debug
+    False
+
+...but if we set it add the two instances together and set the flag on on the
+resulting instance, the other one gets the value too.
+
+    >>> m3 = m1 + m2
+    >>> m3.debug = True
+
+    >>> m1.debug
+    True
+    >>> m2.debug
+    True
+    >>> m3.debug
+    True
+
+    >>> 1
+    2

Modified: manuel/trunk/src/manuel/doctest.py
===================================================================
--- manuel/trunk/src/manuel/doctest.py	2010-08-17 18:05:37 UTC (rev 115746)
+++ manuel/trunk/src/manuel/doctest.py	2010-08-18 00:08:03 UTC (rev 115747)
@@ -62,14 +62,24 @@
     test_name = os.path.split(document.location)[1]
     if m.debug:
         runner = m.debug_runner
+        out = None
     else:
         runner = m.runner
+        out = result.write
 
+    # Use the testrunner-set option flags when running these tests.
+    old_optionflags = runner.optionflags
+    runner.optionflags |= doctest._unittest_reportflags
     runner.DIVIDER = '' # disable unwanted result formatting
+
+    # Here's where everything happens.
+    example = region.parsed
     runner.run(
-        DocTest([region.parsed], globs, test_name,
+        DocTest([example], globs, test_name,
             document.location, region.lineno-1, None),
-        out=result.write, clear_globs=False)
+        out=out, clear_globs=False)
+
+    runner.optionflags = old_optionflags # Reset the option flags.
     region.evaluated = result
 
 
@@ -86,7 +96,6 @@
         self.runner = doctest.DocTestRunner(optionflags=optionflags,
             checker=checker)
         self.debug_runner = doctest.DebugRunner(optionflags=optionflags)
-        self.debug = False
         def evaluate_closure(region, document, globs):
             # capture "self"
             evaluate(self, region, document, globs)



More information about the checkins mailing list