summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-02 22:47:08 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-10-02 22:47:08 (GMT)
commit4a9ac4a83c5515df1b62e396a753ac17a931f997 (patch)
treeba9b99dd884f66df7a3c51e437ce012bac831690 /Lib
parentc15c4f1f39b2b3ca799c9a36b72a7c19a3c76e20 (diff)
downloadcpython-4a9ac4a83c5515df1b62e396a753ac17a931f997.zip
cpython-4a9ac4a83c5515df1b62e396a753ac17a931f997.tar.gz
cpython-4a9ac4a83c5515df1b62e396a753ac17a931f997.tar.bz2
SF patch [#466616] Exclude imported items from doctest.
Another installment; the new functionality wasn't actually enabled in normal use, only in the strained use checked by the test case.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/doctest.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 4689efe..184699a 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -770,7 +770,7 @@ see its docs for details.
>>> m1 = new.module('_m1')
>>> m2 = new.module('_m2')
>>> test_data = \"""
- ... def f():
+ ... def _f():
... '''>>> assert 1 == 1
... '''
... def g():
@@ -785,26 +785,32 @@ see its docs for details.
... \"""
>>> exec test_data in m1.__dict__
>>> exec test_data in m2.__dict__
+ >>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H})
Tests that objects outside m1 are excluded:
- >>> d = {"_f": m1.f, "g": m1.g, "h": m1.H,
- ... "f2": m2.f, "g2": m2.g, "h2": m2.H}
>>> t = Tester(globs={}, verbose=0)
- >>> t.rundict(d, "rundict_test", m1) # _f, f2 and g2 and h2 skipped
+ >>> t.rundict(m1.__dict__, "rundict_test", m1) # _f, f2 and g2 and h2 skipped
(0, 3)
Again, but with a custom isprivate function allowing _f:
>>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
- >>> t.rundict(d, "rundict_test_pvt", m1) # Only f2, g2 and h2 skipped
+ >>> t.rundict(m1.__dict__, "rundict_test_pvt", m1) # Only f2, g2 and h2 skipped
(0, 4)
And once more, not excluding stuff outside m1:
>>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
- >>> t.rundict(d, "rundict_test_pvt") # None are skipped.
+ >>> t.rundict(m1.__dict__, "rundict_test_pvt") # None are skipped.
(0, 8)
+
+ The exclusion of objects from outside the designated module is
+ meant to be invoked automagically by testmod.
+
+ >>> testmod(m1)
+ (0, 3)
+
"""
if not hasattr(d, "items"):
@@ -1037,7 +1043,7 @@ def testmod(m, name=None, globs=None, verbose=None, isprivate=None,
name = m.__name__
tester = Tester(m, globs=globs, verbose=verbose, isprivate=isprivate)
failures, tries = tester.rundoc(m, name)
- f, t = tester.rundict(m.__dict__, name)
+ f, t = tester.rundict(m.__dict__, name, m)
failures = failures + f
tries = tries + t
if hasattr(m, "__test__"):