[Zodb-checkins] CVS: Zope3/src/zope/testing - doctestunit.py:1.11

Nathan Yergler nathan at yergler.net
Fri Apr 2 07:53:11 EST 2004


Update of /cvs-repository/Zope3/src/zope/testing
In directory cvs.zope.org:/tmp/cvs-serv9216/src/zope/testing

Modified Files:
	doctestunit.py 
Log Message:


Added DocFileSuite to allow for easy inclusion of README.txt in tests.py suites.


=== Zope3/src/zope/testing/doctestunit.py 1.10 => 1.11 ===
--- Zope3/src/zope/testing/doctestunit.py:1.10	Tue Mar 30 16:40:02 2004
+++ Zope3/src/zope/testing/doctestunit.py	Fri Apr  2 07:53:05 2004
@@ -87,6 +87,27 @@
     def shortDescription(self):
         return "Doctest: " + self.__name
 
+def DocFileSuite(*paths):
+    # 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.
+    import os, doctest, new
+    t = doctest.Tester(globs={})
+    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 DocTestSuite(module=None,
                  setUp=lambda: None,




More information about the Zodb-checkins mailing list