mirror of
https://github.com/python/cpython.git
synced 2025-09-10 18:58:35 +00:00
bpo-45229: Use doctest.DocTestSuite instead of run_doctest (GH-28468)
Alo use load_tests() for adding tests.
This commit is contained in:
parent
5e2c32e08e
commit
a856364cc9
17 changed files with 117 additions and 183 deletions
|
@ -6,6 +6,7 @@ Original by Michael Schneider
|
||||||
|
|
||||||
import cmd
|
import cmd
|
||||||
import sys
|
import sys
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
import io
|
import io
|
||||||
from test import support
|
from test import support
|
||||||
|
@ -219,10 +220,9 @@ class TestAlternateInput(unittest.TestCase):
|
||||||
"(Cmd) *** Unknown syntax: EOF\n"))
|
"(Cmd) *** Unknown syntax: EOF\n"))
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
from test import test_cmd
|
tests.addTest(doctest.DocTestSuite())
|
||||||
support.run_doctest(test_cmd, verbose)
|
return tests
|
||||||
support.run_unittest(TestAlternateInput)
|
|
||||||
|
|
||||||
def test_coverage(coverdir):
|
def test_coverage(coverdir):
|
||||||
trace = support.import_module('trace')
|
trace = support.import_module('trace')
|
||||||
|
@ -239,4 +239,4 @@ if __name__ == "__main__":
|
||||||
elif "-i" in sys.argv:
|
elif "-i" in sys.argv:
|
||||||
samplecmdclass().cmdloop()
|
samplecmdclass().cmdloop()
|
||||||
else:
|
else:
|
||||||
test_main()
|
unittest.main()
|
||||||
|
|
|
@ -128,6 +128,7 @@ consts: ('None',)
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
import textwrap
|
import textwrap
|
||||||
import weakref
|
import weakref
|
||||||
|
@ -136,7 +137,7 @@ try:
|
||||||
import ctypes
|
import ctypes
|
||||||
except ImportError:
|
except ImportError:
|
||||||
ctypes = None
|
ctypes = None
|
||||||
from test.support import (run_doctest, run_unittest, cpython_only,
|
from test.support import (cpython_only,
|
||||||
check_impl_detail, requires_debug_ranges,
|
check_impl_detail, requires_debug_ranges,
|
||||||
gc_collect)
|
gc_collect)
|
||||||
from test.support.script_helper import assert_python_ok
|
from test.support.script_helper import assert_python_ok
|
||||||
|
@ -609,13 +610,10 @@ if check_impl_detail(cpython=True) and ctypes is not None:
|
||||||
self.assertEqual(LAST_FREED, 500)
|
self.assertEqual(LAST_FREED, 500)
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
from test import test_code
|
tests.addTest(doctest.DocTestSuite())
|
||||||
run_doctest(test_code, verbose)
|
return tests
|
||||||
tests = [CodeTest, CodeConstsTest, CodeWeakRefTest]
|
|
||||||
if check_impl_detail(cpython=True) and ctypes is not None:
|
|
||||||
tests.append(CoExtra)
|
|
||||||
run_unittest(*tests)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
unittest.main()
|
||||||
|
|
|
@ -2351,19 +2351,10 @@ class TestCounter(unittest.TestCase):
|
||||||
self.assertFalse(Counter(a=2, b=1, c=0) > Counter('aab'))
|
self.assertFalse(Counter(a=2, b=1, c=0) > Counter('aab'))
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
def load_tests(loader, tests, pattern):
|
||||||
### Run tests
|
tests.addTest(doctest.DocTestSuite(collections))
|
||||||
################################################################################
|
return 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)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
from test import support, seq_tests
|
from test import support, seq_tests
|
||||||
import gc
|
import gc
|
||||||
|
@ -1033,31 +1034,10 @@ h
|
||||||
|
|
||||||
__test__ = {'libreftest' : libreftest}
|
__test__ = {'libreftest' : libreftest}
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
import sys
|
tests.addTest(doctest.DocTestSuite())
|
||||||
test_classes = (
|
return tests
|
||||||
TestBasic,
|
|
||||||
TestVariousIteratorArgs,
|
|
||||||
TestSubclass,
|
|
||||||
TestSubclassWithKwargs,
|
|
||||||
TestSequence,
|
|
||||||
)
|
|
||||||
|
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
from test.support import sortdict
|
from test.support import sortdict
|
||||||
import pprint
|
import pprint
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class defaultdict(dict):
|
class defaultdict(dict):
|
||||||
def __init__(self, default=None):
|
def __init__(self, default=None):
|
||||||
|
@ -469,19 +472,10 @@ __test__ = {"tut1": test_1,
|
||||||
"tut7": test_7,
|
"tut7": test_7,
|
||||||
"tut8": test_8}
|
"tut8": test_8}
|
||||||
|
|
||||||
# Magic test name that regrtest.py invokes *after* importing this module.
|
def load_tests(loader, tests, pattern):
|
||||||
# This worms around a bootstrap problem.
|
tests.addTest(doctest.DocTestSuite())
|
||||||
# Note that doctest and regrtest both look in sys.argv for a "-v" argument,
|
return tests
|
||||||
# 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.
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(1)
|
unittest.main()
|
||||||
|
|
|
@ -520,11 +520,14 @@ Same with keyword only args:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import doctest
|
||||||
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
def test_main():
|
def load_tests(loader, tests, pattern):
|
||||||
support.run_doctest(sys.modules[__name__], True)
|
tests.addTest(doctest.DocTestSuite())
|
||||||
|
return tests
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
unittest.main()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import copy
|
||||||
import gc
|
import gc
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
import weakref
|
import weakref
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -2371,15 +2372,10 @@ __test__ = {"tut": tutorial_tests,
|
||||||
"refleaks": refleaks_tests,
|
"refleaks": refleaks_tests,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Magic test name that regrtest.py invokes *after* importing this module.
|
def load_tests(loader, tests, pattern):
|
||||||
# This worms around a bootstrap problem.
|
tests.addTest(doctest.DocTestSuite())
|
||||||
# Note that doctest and regrtest both look in sys.argv for a "-v" argument,
|
return tests
|
||||||
# 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)
|
|
||||||
|
|
||||||
# This part isn't needed for regrtest, but for running the test directly.
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(1)
|
unittest.main()
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
import sys
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
doctests = """
|
doctests = """
|
||||||
|
|
||||||
Test simple loop with conditional
|
Test simple loop with conditional
|
||||||
|
@ -274,28 +279,16 @@ Verify that genexps are weakly referencable
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Trace function can throw off the tuple reuse test.
|
# Trace function can throw off the tuple reuse test.
|
||||||
if hasattr(sys, 'gettrace') and sys.gettrace():
|
if hasattr(sys, 'gettrace') and sys.gettrace():
|
||||||
__test__ = {}
|
__test__ = {}
|
||||||
else:
|
else:
|
||||||
__test__ = {'doctests' : doctests}
|
__test__ = {'doctests' : doctests}
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
from test import support
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import test_genexps
|
return tests
|
||||||
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)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Simple test suite for http/cookies.py
|
# Simple test suite for http/cookies.py
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
from test.support import run_unittest, run_doctest
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import doctest
|
||||||
from http import cookies
|
from http import cookies
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
@ -479,9 +479,11 @@ class MorselTests(unittest.TestCase):
|
||||||
r'Set-Cookie: key=coded_val; '
|
r'Set-Cookie: key=coded_val; '
|
||||||
r'expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+')
|
r'expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+')
|
||||||
|
|
||||||
def test_main():
|
|
||||||
run_unittest(CookieTests, MorselTests)
|
def load_tests(loader, tests, pattern):
|
||||||
run_doctest(cookies)
|
tests.addTest(doctest.DocTestSuite(cookies))
|
||||||
|
return tests
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
unittest.main()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
from itertools import *
|
from itertools import *
|
||||||
|
@ -2690,26 +2691,10 @@ True
|
||||||
|
|
||||||
__test__ = {'libreftest' : libreftest}
|
__test__ = {'libreftest' : libreftest}
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
|
tests.addTest(doctest.DocTestSuite())
|
||||||
RegressionTests, LengthTransparency,
|
return tests
|
||||||
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)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
doctests = """
|
doctests = """
|
||||||
########### Tests borrowed from or inspired by test_genexps.py ############
|
########### Tests borrowed from or inspired by test_genexps.py ############
|
||||||
|
|
||||||
|
@ -144,21 +148,10 @@ We also repeat each of the above scoping tests inside a function
|
||||||
|
|
||||||
__test__ = {'doctests' : doctests}
|
__test__ = {'doctests' : doctests}
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
import sys
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import support
|
return tests
|
||||||
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)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
doctests = """
|
doctests = """
|
||||||
|
|
||||||
Basic class construction.
|
Basic class construction.
|
||||||
|
@ -256,10 +260,10 @@ if hasattr(sys, 'gettrace') and sys.gettrace():
|
||||||
else:
|
else:
|
||||||
__test__ = {'doctests' : doctests}
|
__test__ = {'doctests' : doctests}
|
||||||
|
|
||||||
def test_main(verbose=False):
|
def load_tests(loader, tests, pattern):
|
||||||
from test import support
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import test_metaclass
|
return tests
|
||||||
support.run_doctest(test_metaclass, verbose)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
doctests = """
|
doctests = """
|
||||||
########### Tests mostly copied from test_listcomps.py ############
|
########### Tests mostly copied from test_listcomps.py ############
|
||||||
|
|
||||||
|
@ -147,21 +151,10 @@ We also repeat each of the above scoping tests inside a function
|
||||||
|
|
||||||
__test__ = {'doctests' : doctests}
|
__test__ = {'doctests' : doctests}
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def load_tests(loader, tests, pattern):
|
||||||
import sys
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import support
|
return tests
|
||||||
from test import test_setcomps
|
|
||||||
support.run_doctest(test_setcomps, 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_setcomps, verbose)
|
|
||||||
gc.collect()
|
|
||||||
counts[i] = sys.gettotalrefcount()
|
|
||||||
print(counts)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1266,6 +1266,7 @@ Corner-cases that used to crash:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
|
@ -1554,10 +1555,10 @@ while 1:
|
||||||
self._check_error(source, "too many statically nested blocks")
|
self._check_error(source, "too many statically nested blocks")
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def load_tests(loader, tests, pattern):
|
||||||
support.run_unittest(SyntaxTestCase)
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import test_syntax
|
return tests
|
||||||
support.run_doctest(test_syntax, verbosity=True)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
unittest.main()
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
doctests = """
|
doctests = """
|
||||||
|
|
||||||
Unpack tuple
|
Unpack tuple
|
||||||
|
@ -142,10 +146,10 @@ Unpacking to an empty iterable should raise ValueError
|
||||||
|
|
||||||
__test__ = {'doctests' : doctests}
|
__test__ = {'doctests' : doctests}
|
||||||
|
|
||||||
def test_main(verbose=False):
|
def load_tests(loader, tests, pattern):
|
||||||
from test import support
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import test_unpack
|
return tests
|
||||||
support.run_doctest(test_unpack, verbose)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
# Tests for extended unpacking, starred expressions.
|
# Tests for extended unpacking, starred expressions.
|
||||||
|
|
||||||
|
import doctest
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
doctests = """
|
doctests = """
|
||||||
|
|
||||||
Unpack tuple
|
Unpack tuple
|
||||||
|
@ -392,10 +396,10 @@ Some size constraints (all fail.)
|
||||||
|
|
||||||
__test__ = {'doctests' : doctests}
|
__test__ = {'doctests' : doctests}
|
||||||
|
|
||||||
def test_main(verbose=False):
|
def load_tests(loader, tests, pattern):
|
||||||
from test import support
|
tests.addTest(doctest.DocTestSuite())
|
||||||
from test import test_unpack_ex
|
return tests
|
||||||
support.run_doctest(test_unpack_ex, verbose)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main(verbose=True)
|
unittest.main()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import gc
|
import gc
|
||||||
import sys
|
import sys
|
||||||
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
import collections
|
import collections
|
||||||
import weakref
|
import weakref
|
||||||
|
@ -2233,18 +2234,10 @@ OK
|
||||||
|
|
||||||
__test__ = {'libreftest' : libreftest}
|
__test__ = {'libreftest' : libreftest}
|
||||||
|
|
||||||
def test_main():
|
def load_tests(loader, tests, pattern):
|
||||||
support.run_unittest(
|
tests.addTest(doctest.DocTestSuite())
|
||||||
ReferencesTestCase,
|
return tests
|
||||||
WeakMethodTestCase,
|
|
||||||
MappingTestCase,
|
|
||||||
WeakValueDictionaryTestCase,
|
|
||||||
WeakKeyDictionaryTestCase,
|
|
||||||
SubclassableWeakrefTestCase,
|
|
||||||
FinalizeTestCase,
|
|
||||||
)
|
|
||||||
support.run_doctest(sys.modules[__name__])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue