Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3183585

Browse files
committed
Remove deprecated Tester class from doctest module.
1 parent bf086a1 commit 3183585

3 files changed

Lines changed: 16 additions & 215 deletions

File tree

Doc/library/doctest.rst

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ prohibit it by passing ``verbose=False``. In either of those cases,
163163
``sys.argv`` is not examined by :func:`testmod` (so passing :option:`-v` or not
164164
has no effect).
165165

166-
Since Python 2.6, there is also a command line shortcut for running
167-
:func:`testmod`. You can instruct the Python interpreter to run the doctest
168-
module directly from the standard library and pass the module name(s) on the
169-
command line::
166+
There is also a command line shortcut for running :func:`testmod`. You can
167+
instruct the Python interpreter to run the doctest module directly from the
168+
standard library and pass the module name(s) on the command line::
170169

171170
python -m doctest -v example.py
172171

@@ -233,10 +232,9 @@ Like :func:`testmod`, :func:`testfile`'s verbosity can be set with the
233232
:option:`-v` command-line switch or with the optional keyword argument
234233
*verbose*.
235234

236-
Since Python 2.6, there is also a command line shortcut for running
237-
:func:`testfile`. You can instruct the Python interpreter to run the doctest
238-
module directly from the standard library and pass the file name(s) on the
239-
command line::
235+
There is also a command line shortcut for running :func:`testfile`. You can
236+
instruct the Python interpreter to run the doctest module directly from the
237+
standard library and pass the file name(s) on the command line::
240238

241239
python -m doctest -v example.txt
242240

@@ -888,15 +886,10 @@ Unittest API
888886
------------
889887

890888
As your collection of doctest'ed modules grows, you'll want a way to run all
891-
their doctests systematically. Prior to Python 2.4, :mod:`doctest` had a barely
892-
documented :class:`Tester` class that supplied a rudimentary way to combine
893-
doctests from multiple modules. :class:`Tester` was feeble, and in practice most
894-
serious Python testing frameworks build on the :mod:`unittest` module, which
895-
supplies many flexible ways to combine tests from multiple sources. So, in
896-
Python 2.4, :mod:`doctest`'s :class:`Tester` class is deprecated, and
897-
:mod:`doctest` provides two functions that can be used to create :mod:`unittest`
898-
test suites from modules and text files containing doctests. These test suites
899-
can then be run using :mod:`unittest` test runners::
889+
their doctests systematically. :mod:`doctest` provides two functions that can
890+
be used to create :mod:`unittest` test suites from modules and text files
891+
containing doctests. These test suites can then be run using :mod:`unittest`
892+
test runners::
900893

901894
import unittest
902895
import doctest

Lib/doctest.py

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ def register_optionflag(name):
166166
# 4. DocTest Finder -- extracts test cases from objects
167167
# 5. DocTest Runner -- runs test cases
168168
# 6. Test Functions -- convenient wrappers for testing
169-
# 7. Tester Class -- for backwards compatibility
170-
# 8. Unittest Support
171-
# 9. Debugging Support
172-
# 10. Example Usage
169+
# 7. Unittest Support
170+
# 8. Debugging Support
171+
# 9. Example Usage
173172

174173
######################################################################
175174
## 1. Utility Functions
@@ -1968,72 +1967,7 @@ def run_docstring_examples(f, globs, verbose=False, name="NoName",
19681967
runner.run(test, compileflags=compileflags)
19691968

19701969
######################################################################
1971-
## 7. Tester
1972-
######################################################################
1973-
# This is provided only for backwards compatibility. It's not
1974-
# actually used in any way.
1975-
1976-
class Tester:
1977-
def __init__(self, mod=None, globs=None, verbose=None, optionflags=0):
1978-
1979-
warnings.warn("class Tester is deprecated; "
1980-
"use class doctest.DocTestRunner instead",
1981-
DeprecationWarning, stacklevel=2)
1982-
if mod is None and globs is None:
1983-
raise TypeError("Tester.__init__: must specify mod or globs")
1984-
if mod is not None and not inspect.ismodule(mod):
1985-
raise TypeError("Tester.__init__: mod must be a module; %r" %
1986-
(mod,))
1987-
if globs is None:
1988-
globs = mod.__dict__
1989-
self.globs = globs
1990-
1991-
self.verbose = verbose
1992-
self.optionflags = optionflags
1993-
self.testfinder = DocTestFinder()
1994-
self.testrunner = DocTestRunner(verbose=verbose,
1995-
optionflags=optionflags)
1996-
1997-
def runstring(self, s, name):
1998-
test = DocTestParser().get_doctest(s, self.globs, name, None, None)
1999-
if self.verbose:
2000-
print("Running string", name)
2001-
(f,t) = self.testrunner.run(test)
2002-
if self.verbose:
2003-
print(f, "of", t, "examples failed in string", name)
2004-
return TestResults(f,t)
2005-
2006-
def rundoc(self, object, name=None, module=None):
2007-
f = t = 0
2008-
tests = self.testfinder.find(object, name, module=module,
2009-
globs=self.globs)
2010-
for test in tests:
2011-
(f2, t2) = self.testrunner.run(test)
2012-
(f,t) = (f+f2, t+t2)
2013-
return TestResults(f,t)
2014-
2015-
def rundict(self, d, name, module=None):
2016-
import types
2017-
m = types.ModuleType(name)
2018-
m.__dict__.update(d)
2019-
if module is None:
2020-
module = False
2021-
return self.rundoc(m, name, module)
2022-
2023-
def run__test__(self, d, name):
2024-
import types
2025-
m = types.ModuleType(name)
2026-
m.__test__ = d
2027-
return self.rundoc(m, name)
2028-
2029-
def summarize(self, verbose=None):
2030-
return self.testrunner.summarize(verbose)
2031-
2032-
def merge(self, other):
2033-
self.testrunner.merge(other.testrunner)
2034-
2035-
######################################################################
2036-
## 8. Unittest Support
1970+
## 7. Unittest Support
20371971
######################################################################
20381972

20391973
_unittest_reportflags = 0
@@ -2393,7 +2327,7 @@ def DocFileSuite(*paths, **kw):
23932327
return suite
23942328

23952329
######################################################################
2396-
## 9. Debugging Support
2330+
## 8. Debugging Support
23972331
######################################################################
23982332

23992333
def script_from_examples(s):
@@ -2546,7 +2480,7 @@ def debug(module, name, pm=False):
25462480
debug_script(testsrc, pm, module.__dict__)
25472481

25482482
######################################################################
2549-
## 10. Example Usage
2483+
## 9. Example Usage
25502484
######################################################################
25512485
class _TestClass:
25522486
"""

Lib/test/test_doctest.py

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,132 +2285,6 @@ def test_testfile(): r"""
22852285
>>> doctest.master = None # Reset master.
22862286
"""
22872287

2288-
# old_test1, ... used to live in doctest.py, but cluttered it. Note
2289-
# that these use the deprecated doctest.Tester, so should go away (or
2290-
# be rewritten) someday.
2291-
2292-
# Ignore all warnings about the use of class Tester in this module.
2293-
# Note that the name of this module may differ depending on how it's
2294-
# imported, so the use of __name__ is important.
2295-
warnings.filterwarnings("ignore", "class Tester", DeprecationWarning,
2296-
__name__, 0)
2297-
2298-
def old_test1(): r"""
2299-
>>> from doctest import Tester
2300-
>>> t = Tester(globs={'x': 42}, verbose=0)
2301-
>>> t.runstring(r'''
2302-
... >>> x = x * 2
2303-
... >>> print(x)
2304-
... 42
2305-
... ''', 'XYZ')
2306-
**********************************************************************
2307-
Line 3, in XYZ
2308-
Failed example:
2309-
print(x)
2310-
Expected:
2311-
42
2312-
Got:
2313-
84
2314-
TestResults(failed=1, attempted=2)
2315-
>>> t.runstring(">>> x = x * 2\n>>> print(x)\n84\n", 'example2')
2316-
TestResults(failed=0, attempted=2)
2317-
>>> t.summarize()
2318-
**********************************************************************
2319-
1 items had failures:
2320-
1 of 2 in XYZ
2321-
***Test Failed*** 1 failures.
2322-
TestResults(failed=1, attempted=4)
2323-
>>> t.summarize(verbose=1)
2324-
1 items passed all tests:
2325-
2 tests in example2
2326-
**********************************************************************
2327-
1 items had failures:
2328-
1 of 2 in XYZ
2329-
4 tests in 2 items.
2330-
3 passed and 1 failed.
2331-
***Test Failed*** 1 failures.
2332-
TestResults(failed=1, attempted=4)
2333-
"""
2334-
2335-
def old_test2(): r"""
2336-
>>> from doctest import Tester
2337-
>>> t = Tester(globs={}, verbose=1)
2338-
>>> test = r'''
2339-
... # just an example
2340-
... >>> x = 1 + 2
2341-
... >>> x
2342-
... 3
2343-
... '''
2344-
>>> t.runstring(test, "Example")
2345-
Running string Example
2346-
Trying:
2347-
x = 1 + 2
2348-
Expecting nothing
2349-
ok
2350-
Trying:
2351-
x
2352-
Expecting:
2353-
3
2354-
ok
2355-
0 of 2 examples failed in string Example
2356-
TestResults(failed=0, attempted=2)
2357-
"""
2358-
2359-
def old_test3(): r"""
2360-
>>> from doctest import Tester
2361-
>>> t = Tester(globs={}, verbose=0)
2362-
>>> def _f():
2363-
... '''Trivial docstring example.
2364-
... >>> assert 2 == 2
2365-
... '''
2366-
... return 32
2367-
...
2368-
>>> t.rundoc(_f) # expect 0 failures in 1 example
2369-
TestResults(failed=0, attempted=1)
2370-
"""
2371-
2372-
def old_test4(): """
2373-
>>> import types
2374-
>>> m1 = types.ModuleType('_m1')
2375-
>>> m2 = types.ModuleType('_m2')
2376-
>>> test_data = \"""
2377-
... def _f():
2378-
... '''>>> assert 1 == 1
2379-
... '''
2380-
... def g():
2381-
... '''>>> assert 2 != 1
2382-
... '''
2383-
... class H:
2384-
... '''>>> assert 2 > 1
2385-
... '''
2386-
... def bar(self):
2387-
... '''>>> assert 1 < 2
2388-
... '''
2389-
... \"""
2390-
>>> exec(test_data, m1.__dict__)
2391-
>>> exec(test_data, m2.__dict__)
2392-
>>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H})
2393-
2394-
Tests that objects outside m1 are excluded:
2395-
2396-
>>> from doctest import Tester
2397-
>>> t = Tester(globs={}, verbose=0)
2398-
>>> t.rundict(m1.__dict__, "rundict_test", m1) # f2 and g2 and h2 skipped
2399-
TestResults(failed=0, attempted=4)
2400-
2401-
Once more, not excluding stuff outside m1:
2402-
2403-
>>> t = Tester(globs={}, verbose=0)
2404-
>>> t.rundict(m1.__dict__, "rundict_test_pvt") # None are skipped.
2405-
TestResults(failed=0, attempted=8)
2406-
2407-
The exclusion of objects from outside the designated module is
2408-
meant to be invoked automagically by testmod.
2409-
2410-
>>> doctest.testmod(m1, verbose=False)
2411-
TestResults(failed=0, attempted=4)
2412-
"""
2413-
24142288
######################################################################
24152289
## Main
24162290
######################################################################

0 commit comments

Comments
 (0)