From 4a9ac4a83c5515df1b62e396a753ac17a931f997 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Tue, 2 Oct 2001 22:47:08 +0000 Subject: [PATCH] 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. --- Lib/doctest.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Lib/doctest.py b/Lib/doctest.py index 4689efed1b6..184699a84b2 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__"):