[Zope3-checkins] CVS: Zope3/src/zope/interface/tests - docfilesuite.py:1.1 test_adapter.py:1.5

Jim Fulton jim at zope.com
Mon Apr 5 15:43:43 EDT 2004


Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv13137/src/zope/interface/tests

Modified Files:
	test_adapter.py 
Added Files:
	docfilesuite.py 
Log Message:
Factored function to compute a test suite from a .txt file into a
separate module.


=== Added File Zope3/src/zope/interface/tests/docfilesuite.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Utility to create doc tests from readme files

$Id: docfilesuite.py,v 1.1 2004/04/05 19:43:41 jim Exp $
"""

import os, doctest, new, unittest

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


=== Zope3/src/zope/interface/tests/test_adapter.py 1.4 => 1.5 ===
--- Zope3/src/zope/interface/tests/test_adapter.py:1.4	Mon Mar 15 15:41:55 2004
+++ Zope3/src/zope/interface/tests/test_adapter.py	Mon Apr  5 15:43:41 2004
@@ -198,30 +198,9 @@
 
 
 
-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 test_suite():
+    from docfilesuite import DocFileSuite
     return unittest.TestSuite((
         DocFileSuite('../adapter.txt', 'foodforthought.txt'),
         doctest.DocTestSuite('zope.interface.adapter'),




More information about the Zope3-Checkins mailing list