[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Changed the test-counting mechanism for doctests. Now a doctest

Jim Fulton jim at zope.com
Thu Dec 16 16:48:50 EST 2004


Log message for revision 28639:
  Changed the test-counting mechanism for doctests.  Now a doctest
  count a test for every example that is preceeded by
  prose. (Although a doctest will never count less than 1 test.)
  

Changed:
  U   Zope3/trunk/src/zope/app/tests/test.py
  U   Zope3/trunk/src/zope/testing/doctest.py

-=-
Modified: Zope3/trunk/src/zope/app/tests/test.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/test.py	2004-12-16 21:22:58 UTC (rev 28638)
+++ Zope3/trunk/src/zope/app/tests/test.py	2004-12-16 21:48:49 UTC (rev 28639)
@@ -369,9 +369,14 @@
                 self._lastWidth = width
             self.stream.flush()
         self._threads = threading.enumerate()
+
         self.__super_startTest(test)
+        # the super version can't count. ;)
+        self.testsRun += test.countTestCases() - 1
+
         self._testtimes[test] = time.time()
 
+
     def getShortDescription(self, test):
         s = self.getDescription(test)
         if len(s) > self._maxWidth:

Modified: Zope3/trunk/src/zope/testing/doctest.py
===================================================================
--- Zope3/trunk/src/zope/testing/doctest.py	2004-12-16 21:22:58 UTC (rev 28638)
+++ Zope3/trunk/src/zope/testing/doctest.py	2004-12-16 21:48:49 UTC (rev 28639)
@@ -2102,7 +2102,24 @@
     _unittest_reportflags = flags
     return old
 
-
+_para_re = re.compile('\s*\n\s*\n\s*')
+def _unittest_count(docstring):
+    words = 0
+    count = 0
+    for p in _para_re.split(docstring):
+        p = p.strip()
+        if not p:
+            continue
+        if p.startswith('>>> '):
+            if words:
+                count += 1
+                words = 0
+        else:
+            words = 1
+            
+    return count or 1
+            
+    
 class DocTestCase(unittest.TestCase):
 
     def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
@@ -2115,6 +2132,11 @@
         self._dt_setUp = setUp
         self._dt_tearDown = tearDown
 
+        self._dt_count = _unittest_count(test.docstring)
+
+    def countTestCases(self):
+        return self._dt_count
+
     def setUp(self):
         test = self._dt_test
 



More information about the Zope3-Checkins mailing list