Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-45229: Use doctest.DocTestSuite instead of run_doctest #28468

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Lib/test/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import cmd
import sys
import doctest
import unittest
import io
from test import support
Expand Down Expand Up @@ -219,10 +220,9 @@ def test_input_reset_at_EOF(self):
"(Cmd) *** Unknown syntax: EOF\n"))


def test_main(verbose=None):
from test import test_cmd
support.run_doctest(test_cmd, verbose)
support.run_unittest(TestAlternateInput)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests

def test_coverage(coverdir):
trace = support.import_module('trace')
Expand All @@ -239,4 +239,4 @@ def test_coverage(coverdir):
elif "-i" in sys.argv:
samplecmdclass().cmdloop()
else:
test_main()
unittest.main()
16 changes: 7 additions & 9 deletions Lib/test/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import inspect
import sys
import threading
import doctest
import unittest
import textwrap
import weakref
Expand All @@ -136,7 +137,7 @@
import ctypes
except ImportError:
ctypes = None
from test.support import (run_doctest, run_unittest, cpython_only,
from test.support import (cpython_only,
check_impl_detail, requires_debug_ranges,
gc_collect)
from test.support.script_helper import assert_python_ok
Expand Down Expand Up @@ -609,13 +610,10 @@ def run(self):
self.assertEqual(LAST_FREED, 500)


def test_main(verbose=None):
from test import test_code
run_doctest(test_code, verbose)
tests = [CodeTest, CodeConstsTest, CodeWeakRefTest]
if check_impl_detail(cpython=True) and ctypes is not None:
tests.append(CoExtra)
run_unittest(*tests)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == "__main__":
test_main()
unittest.main()
17 changes: 4 additions & 13 deletions Lib/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2351,19 +2351,10 @@ def test_gt(self):
self.assertFalse(Counter(a=2, b=1, c=0) > Counter('aab'))


################################################################################
### Run tests
################################################################################

def test_main(verbose=None):
NamedTupleDocs = doctest.DocTestSuite(module=collections)
test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
TestCollectionABCs, TestCounter, TestChainMap,
TestUserObjects,
]
support.run_unittest(*test_classes)
support.run_doctest(collections, verbose)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(collections))
return tests


if __name__ == "__main__":
test_main(verbose=True)
unittest.main()
30 changes: 5 additions & 25 deletions Lib/test/test_deque.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import deque
import doctest
import unittest
from test import support, seq_tests
import gc
Expand Down Expand Up @@ -1033,31 +1034,10 @@ def test_free_after_iterating(self):

__test__ = {'libreftest' : libreftest}

def test_main(verbose=None):
import sys
test_classes = (
TestBasic,
TestVariousIteratorArgs,
TestSubclass,
TestSubclassWithKwargs,
TestSequence,
)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests

support.run_unittest(*test_classes)

# verify reference counting
if verbose and hasattr(sys, "gettotalrefcount"):
import gc
counts = [None] * 5
for i in range(len(counts)):
support.run_unittest(*test_classes)
gc.collect()
counts[i] = sys.gettotalrefcount()
print(counts)

# doctests
from test import test_deque
support.run_doctest(test_deque, verbose)

if __name__ == "__main__":
test_main(verbose=True)
unittest.main()
24 changes: 9 additions & 15 deletions Lib/test/test_descrtut.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from test.support import sortdict
import pprint
import doctest
import unittest


class defaultdict(dict):
def __init__(self, default=None):
Expand Down Expand Up @@ -469,19 +472,10 @@ def m(self):
"tut7": test_7,
"tut8": test_8}

# Magic test name that regrtest.py invokes *after* importing this module.
# This worms around a bootstrap problem.
# Note that doctest and regrtest both look in sys.argv for a "-v" argument,
# so this works as expected in both ways of running regrtest.
def test_main(verbose=None):
# Obscure: import this module as test.test_descrtut instead of as
# plain test_descrtut because the name of this module works its way
# into the doctest examples, and unless the full test.test_descrtut
# business is used the name can change depending on how the test is
# invoked.
from test import support, test_descrtut
support.run_doctest(test_descrtut, verbose)

# This part isn't needed for regrtest, but for running the test directly.
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == "__main__":
test_main(1)
unittest.main()
11 changes: 7 additions & 4 deletions Lib/test/test_extcall.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,14 @@
"""

import sys
import doctest
import unittest
from test import support

def test_main():
support.run_doctest(sys.modules[__name__], True)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == '__main__':
test_main()
unittest.main()
16 changes: 6 additions & 10 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gc
import pickle
import sys
import doctest
import unittest
import weakref
import inspect
Expand Down Expand Up @@ -2371,15 +2372,10 @@ def printsolution(self, x):
"refleaks": refleaks_tests,
}

# Magic test name that regrtest.py invokes *after* importing this module.
# This worms around a bootstrap problem.
# Note that doctest and regrtest both look in sys.argv for a "-v" argument,
# so this works as expected in both ways of running regrtest.
def test_main(verbose=None):
from test import support, test_generators
support.run_unittest(__name__)
support.run_doctest(test_generators, verbose)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


# This part isn't needed for regrtest, but for running the test directly.
if __name__ == "__main__":
test_main(1)
unittest.main()
27 changes: 10 additions & 17 deletions Lib/test/test_genexps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import sys
import doctest
import unittest


doctests = """

Test simple loop with conditional
Expand Down Expand Up @@ -274,28 +279,16 @@

"""

import sys

# Trace function can throw off the tuple reuse test.
if hasattr(sys, 'gettrace') and sys.gettrace():
__test__ = {}
else:
__test__ = {'doctests' : doctests}

def test_main(verbose=None):
from test import support
from test import test_genexps
support.run_doctest(test_genexps, verbose)

# verify reference counting
if verbose and hasattr(sys, "gettotalrefcount"):
import gc
counts = [None] * 5
for i in range(len(counts)):
support.run_doctest(test_genexps, verbose)
gc.collect()
counts[i] = sys.gettotalrefcount()
print(counts)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == "__main__":
test_main(verbose=True)
unittest.main()
12 changes: 7 additions & 5 deletions Lib/test/test_http_cookies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Simple test suite for http/cookies.py

import copy
from test.support import run_unittest, run_doctest
import unittest
import doctest
from http import cookies
import pickle

Expand Down Expand Up @@ -479,9 +479,11 @@ def test_repr(self):
r'Set-Cookie: key=coded_val; '
r'expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+')

def test_main():
run_unittest(CookieTests, MorselTests)
run_doctest(cookies)

def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(cookies))
return tests


if __name__ == '__main__':
test_main()
unittest.main()
27 changes: 6 additions & 21 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import doctest
import unittest
from test import support
from itertools import *
Expand Down Expand Up @@ -2689,26 +2690,10 @@ def test_permutations_sizeof(self):

__test__ = {'libreftest' : libreftest}

def test_main(verbose=None):
test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
RegressionTests, LengthTransparency,
SubclassWithKwargsTest, TestExamples,
TestPurePythonRoughEquivalents,
SizeofTest)
support.run_unittest(*test_classes)

# verify reference counting
if verbose and hasattr(sys, "gettotalrefcount"):
import gc
counts = [None] * 5
for i in range(len(counts)):
support.run_unittest(*test_classes)
gc.collect()
counts[i] = sys.gettotalrefcount()
print(counts)

# doctest the examples in the library reference
support.run_doctest(sys.modules[__name__], verbose)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == "__main__":
test_main(verbose=True)
unittest.main()
25 changes: 9 additions & 16 deletions Lib/test/test_listcomps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import doctest
import unittest


doctests = """
########### Tests borrowed from or inspired by test_genexps.py ############

Expand Down Expand Up @@ -144,21 +148,10 @@

__test__ = {'doctests' : doctests}

def test_main(verbose=None):
import sys
from test import support
from test import test_listcomps
support.run_doctest(test_listcomps, verbose)

# verify reference counting
if verbose and hasattr(sys, "gettotalrefcount"):
import gc
counts = [None] * 5
for i in range(len(counts)):
support.run_doctest(test_listcomps, verbose)
gc.collect()
counts[i] = sys.gettotalrefcount()
print(counts)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == "__main__":
test_main(verbose=True)
unittest.main()
14 changes: 9 additions & 5 deletions Lib/test/test_metaclass.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import doctest
import unittest


doctests = """

Basic class construction.
Expand Down Expand Up @@ -256,10 +260,10 @@
else:
__test__ = {'doctests' : doctests}

def test_main(verbose=False):
from test import support
from test import test_metaclass
support.run_doctest(test_metaclass, verbose)
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests


if __name__ == "__main__":
test_main(verbose=True)
unittest.main()
Loading