]> granicus.if.org Git - python/commitdiff
exclude_empty: make the default True for DocTestFinder, and introduce it
authorTim Peters <tim.peters@gmail.com>
Mon, 13 Sep 2004 14:53:28 +0000 (14:53 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 13 Sep 2004 14:53:28 +0000 (14:53 +0000)
with default False for testmod().  The real point of introducing this was
so that output from doctest.master.summarize() would be the same as in
2.3, and doctest.master in 2.4 is a backward-compatability hack used only
by testmod().

Lib/doctest.py
Lib/test/test_doctest.py

index 156ef57ca1deb0e5a2c0665431fa96aee8c4aa9d..c1a87b38811c3dbf56a1150fe02de5945ab34ffd 100644 (file)
@@ -848,8 +848,7 @@ class DocTestFinder:
     """
 
     def __init__(self, verbose=False, parser=DocTestParser(),
-                 recurse=True, _namefilter=None,
-                 exclude_empty=False):
+                 recurse=True, _namefilter=None, exclude_empty=True):
         """
         Create a new doctest finder.
 
@@ -862,8 +861,8 @@ class DocTestFinder:
         If the optional argument `recurse` is false, then `find` will
         only examine the given object, and not any contained objects.
 
-        If the optional argument `exclude_empty` is true, then `find`
-        will exclude tests for objects with empty docstrings.
+        If the optional argument `exclude_empty` is false, then `find`
+        will include tests for objects with empty docstrings.
         """
         self._parser = parser
         self._verbose = verbose
@@ -1836,9 +1835,10 @@ master = None
 
 def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
             report=True, optionflags=0, extraglobs=None,
-            raise_on_error=False):
+            raise_on_error=False, exclude_empty=False):
     """m=None, name=None, globs=None, verbose=None, isprivate=None,
-       report=True, optionflags=0, extraglobs=None
+       report=True, optionflags=0, extraglobs=None, raise_on_error=False,
+       exclude_empty=False
 
     Test examples in docstrings in functions and classes reachable
     from module m (or the current module if m is not supplied), starting
@@ -1930,7 +1930,7 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
         name = m.__name__
 
     # Find, parse, and run all tests in the given module.
-    finder = DocTestFinder(_namefilter=isprivate)
+    finder = DocTestFinder(_namefilter=isprivate, exclude_empty=exclude_empty)
 
     if raise_on_error:
         runner = DebugRunner(verbose=verbose, optionflags=optionflags)
index a304f5cb27d5a396a06ef3a1c2c0caacb9d0b060..77b9ef541e477cd79a5746232e14f6dcf25960b5 100644 (file)
@@ -377,8 +377,8 @@ By default, tests are created for objects with no docstring:
 
     >>> def no_docstring(v):
     ...     pass
-    >>> finder.find(no_docstring) # doctest: +ELLIPSIS
-    [<DocTest no_docstring from ... (no examples)>]
+    >>> finder.find(no_docstring)
+    []
 
 However, the optional argument `exclude_empty` to the DocTestFinder
 constructor can be used to exclude tests for objects with empty
@@ -414,8 +414,6 @@ methods, classmethods, staticmethods, properties, and nested classes.
      1  SampleClass
      3  SampleClass.NestedClass
      1  SampleClass.NestedClass.__init__
-     0  SampleClass.NestedClass.get
-     0  SampleClass.NestedClass.square
      1  SampleClass.__init__
      2  SampleClass.a_classmethod
      1  SampleClass.a_property
@@ -473,8 +471,6 @@ functions, classes, and the `__test__` dictionary, if it exists:
      1  some_module.SampleClass
      3  some_module.SampleClass.NestedClass
      1  some_module.SampleClass.NestedClass.__init__
-     0  some_module.SampleClass.NestedClass.get
-     0  some_module.SampleClass.NestedClass.square
      1  some_module.SampleClass.__init__
      2  some_module.SampleClass.a_classmethod
      1  some_module.SampleClass.a_property
@@ -516,6 +512,23 @@ deprecated isprivate gimmick.
     >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass)
     >>> tests.sort()
     >>> for t in tests:
+    ...     print '%2s  %s' % (len(t.examples), t.name)
+     1  SampleClass
+     3  SampleClass.NestedClass
+     1  SampleClass.NestedClass.__init__
+     1  SampleClass.__init__
+     1  SampleClass.double
+     1  SampleClass.get
+
+By default, that excluded objects with no doctests.  exclude_empty=False
+tells it to include (empty) tests for objects with no doctests.  This feature
+is really to support backward compatibility in what doctest.master.summarize()
+displays.
+
+    >>> tests = doctest.DocTestFinder(_namefilter=namefilter,
+    ...                                exclude_empty=False).find(SampleClass)
+    >>> tests.sort()
+    >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      1  SampleClass
      3  SampleClass.NestedClass
@@ -550,7 +563,7 @@ object explicitly passed to DocTestFinder:
     ...     return base == 'SampleClass'
     >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass)
     >>> len(tests)
-    11
+    9
 
 Turning off Recursion
 ~~~~~~~~~~~~~~~~~~~~~