[Zope3-checkins] SVN: Zope3/trunk/src/ Updated to work with the versions of doctest from Python with versions

Jim Fulton jim at zope.com
Fri Aug 6 18:30:44 EDT 2004


Log message for revision 26945:
  
  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/trunk/src/persistent/tests/test_persistent.py
  U   Zope3/trunk/src/zope/event/tests.py


-=-
Modified: Zope3/trunk/src/persistent/tests/test_persistent.py
===================================================================
--- Zope3/trunk/src/persistent/tests/test_persistent.py	2004-08-06 19:15:09 UTC (rev 26944)
+++ Zope3/trunk/src/persistent/tests/test_persistent.py	2004-08-06 22:30:44 UTC (rev 26945)
@@ -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/trunk/src/zope/event/tests.py
===================================================================
--- Zope3/trunk/src/zope/event/tests.py	2004-08-06 19:15:09 UTC (rev 26944)
+++ Zope3/trunk/src/zope/event/tests.py	2004-08-06 22:30:44 UTC (rev 26945)
@@ -18,31 +18,36 @@
 
 import os, doctest, new, unittest
 
-def DocFileSuite(*paths):
-    """Utility to create doc tests from readme files
+try:
+    DocFileSuite = doctest.DocFileSuite # >= Python 2.4.0a2
+except AttributeError:
+    # <= Python 2.4.0a1
 
-    Eventually, this, or something like it, will be part of doctest
-    """
-    # 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.dirname(__file__)
-    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 DocFileSuite(*paths):
+        """Utility to create doc tests from readme files
 
+        Eventually, this, or something like it, will be part of doctest
+        """
+        # 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 unittest.TestSuite((
         DocFileSuite('README.txt'),



More information about the Zope3-Checkins mailing list