[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/ Merged from trunk:

Jim Fulton jim at zope.com
Wed Aug 11 14:19:52 EDT 2004


Log message for revision 27011:
  Merged from trunk:
  
    r26945 | jim | 2004-08-06 18:30:44 -0400 (Fri, 06 Aug 2004) | 6 lines
  
  
  Updated to work with the versions of doctest from Python with versions
    greater than or equal to 2.3.0 and less than 2.4.0.a2 and with
    versions greater than 2.4.0a2.
  
  
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/persistent/tests/test_persistent.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/event/tests.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/persistent/tests/test_persistent.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/persistent/tests/test_persistent.py	2004-08-11 18:09:47 UTC (rev 27010)
+++ Zope3/branches/ZopeX3-3.0/src/persistent/tests/test_persistent.py	2004-08-11 18:19:52 UTC (rev 27011)
@@ -25,23 +25,30 @@
     def inc(self):
         self.x += 1
 
-def DocFileSuite(path, globs=None):
-    # It's not entirely obvious how to connection this single string
-    # with unittest.  For now, re-use the _utest() function that comes
-    # standard with doctest in Python 2.3.  One problem is that the
-    # error indicator doesn't point to the line of the doctest file
-    # that failed.
-    source = open(path).read()
-    if globs is None:
-        globs = sys._getframe(1).f_globals
-    t = doctest.Tester(globs=globs)
-    def runit():
-        doctest._utest(t, path, source, path, 0)
-    f = unittest.FunctionTestCase(runit, description="doctest from %s" % path)
-    suite = unittest.TestSuite()
-    suite.addTest(f)
-    return suite
+try:
+    DocFileSuite = doctest.DocFileSuite # >= Python 2.4.0a2
+except AttributeError:
+    # <= Python 2.4.0a1
+    def DocFileSuite(path, globs=None):
+        # It's not entirely obvious how to connection this single string
+        # with unittest.  For now, re-use the _utest() function that comes
+        # standard with doctest in Python 2.3.  One problem is that the
+        # error indicator doesn't point to the line of the doctest file
+        # that failed.
 
+        path = os.path.join(persistent.tests.__path__[0], path)
+        
+        source = open(path).read()
+        if globs is None:
+            globs = sys._getframe(1).f_globals
+        t = doctest.Tester(globs=globs)
+        def runit():
+            doctest._utest(t, path, source, path, 0)
+        f = unittest.FunctionTestCase(runit,
+                                      description="doctest from %s" % path)
+        suite = unittest.TestSuite()
+        suite.addTest(f)
+        return suite
+
 def test_suite():
-    path = os.path.join(persistent.tests.__path__[0], "persistent.txt")
-    return DocFileSuite(path, {"P": P})
+    return DocFileSuite("persistent.txt", globs={"P": P})

Modified: Zope3/branches/ZopeX3-3.0/src/zope/event/tests.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/event/tests.py	2004-08-11 18:09:47 UTC (rev 27010)
+++ Zope3/branches/ZopeX3-3.0/src/zope/event/tests.py	2004-08-11 18:19:52 UTC (rev 27011)
@@ -20,7 +20,34 @@
 
 from zope.testing import doctest
 
+try:
+    DocFileSuite = doctest.DocFileSuite # >= Python 2.4.0a2
+except AttributeError:
+    # <= Python 2.4.0a1
 
+    def DocFileSuite(*paths):
+        """Utility to create doc tests from readme files
+        """
+        # It's not entirely obvious how to connection this single string
+        # with unittest.  For now, re-use the _utest() function that comes
+        # standard with doctest in Python 2.3.  One problem is that the
+        # error indicator doesn't point to the line of the doctest file
+        # that failed.
+        t = doctest.Tester(globs={'__name__': '__main__'})
+        suite = unittest.TestSuite()
+        dir = os.path.split(__file__)[0]
+        for path in paths:
+            path = os.path.join(dir, path)
+            source = open(path).read()
+            def runit(path=path, source=source):
+                doctest._utest(t, path, source, path, 0)
+            runit = new.function(runit.func_code, runit.func_globals, path,
+                                 runit.func_defaults, runit.func_closure)
+            f = unittest.FunctionTestCase(runit,
+                                          description="doctest from %s" % path)
+            suite.addTest(f)
+        return suite
+
 def test_suite():
     return doctest.DocFileSuite('README.txt')
 



More information about the Zope3-Checkins mailing list