Update doctest from v3.14.2

This commit is contained in:
CPython Developers authored and Jeong, YunWon committed 2026-02-11 16:47:03 +09:00
1 parent 5c341efdf0
commit e616f250af
2 files changed
+1267 -1423

No files matched your search

+18 -16
View File
@@ -109,6 +109,8 @@ import _colorize # Used in doctests
from _colorize import ANSIColors, can_colorize
__unittest = True
class TestResults(namedtuple('TestResults', 'failed attempted')):
def __new__(cls, failed, attempted, *, skipped=0):
results = super().__new__(cls, failed, attempted)
@@ -390,11 +392,11 @@ class _OutputRedirectingPdb(pdb.Pdb):
# still use input() to get user input
self.use_rawinput = 1
def set_trace(self, frame=None):
def set_trace(self, frame=None, *, commands=None):
self.__debugger_used = True
if frame is None:
frame = sys._getframe().f_back
pdb.Pdb.set_trace(self, frame)
pdb.Pdb.set_trace(self, frame, commands=commands)
def set_continue(self):
# Calling set_continue unconditionally would break unit test
@@ -1230,7 +1232,7 @@ class DocTestRunner:
`OutputChecker` to the constructor.
The test runner's display output can be controlled in two ways.
First, an output function (`out) can be passed to
First, an output function (`out`) can be passed to
`TestRunner.run`; this function will be called with strings that
should be displayed. It defaults to `sys.stdout.write`. If
capturing the output is not sufficient, then the display output
@@ -1398,11 +1400,11 @@ class DocTestRunner:
exec(compile(example.source, filename, "single",
compileflags, True), test.globs)
self.debugger.set_continue() # ==== Example Finished ====
exception = None
exc_info = None
except KeyboardInterrupt:
raise
except:
exception = sys.exc_info()
except BaseException as exc:
exc_info = type(exc), exc, exc.__traceback__.tb_next
self.debugger.set_continue() # ==== Example Finished ====
got = self._fakeout.getvalue() # the actual output
@@ -1411,21 +1413,21 @@ class DocTestRunner:
# If the example executed without raising any exceptions,
# verify its output.
if exception is None:
if exc_info is None:
if check(example.want, got, self.optionflags):
outcome = SUCCESS
# The example raised an exception: check if it was expected.
else:
formatted_ex = traceback.format_exception_only(*exception[:2])
if issubclass(exception[0], SyntaxError):
formatted_ex = traceback.format_exception_only(*exc_info[:2])
if issubclass(exc_info[0], SyntaxError):
# SyntaxError / IndentationError is special:
# we don't care about the carets / suggestions / etc
# We only care about the error message and notes.
# They start with `SyntaxError:` (or any other class name)
exception_line_prefixes = (
f"{exception[0].__qualname__}:",
f"{exception[0].__module__}.{exception[0].__qualname__}:",
f"{exc_info[0].__qualname__}:",
f"{exc_info[0].__module__}.{exc_info[0].__qualname__}:",
)
exc_msg_index = next(
index
@@ -1436,7 +1438,7 @@ class DocTestRunner:
exc_msg = "".join(formatted_ex)
if not quiet:
got += _exception_traceback(exception)
got += _exception_traceback(exc_info)
# If `example.exc_msg` is None, then we weren't expecting
# an exception.
@@ -1465,7 +1467,7 @@ class DocTestRunner:
elif outcome is BOOM:
if not quiet:
self.report_unexpected_exception(out, test, example,
exception)
exc_info)
failures += 1
else:
assert False, ("unknown outcome", outcome)
@@ -2327,7 +2329,7 @@ class DocTestCase(unittest.TestCase):
sys.stdout = old
if results.failed:
raise self.failureException(self.format_failure(new.getvalue()))
raise self.failureException(self.format_failure(new.getvalue().rstrip('\n')))
def format_failure(self, err):
test = self._dt_test
@@ -2737,7 +2739,7 @@ def testsource(module, name):
return testsrc
def debug_src(src, pm=False, globs=None):
"""Debug a single doctest docstring, in argument `src`'"""
"""Debug a single doctest docstring, in argument `src`"""
testsrc = script_from_examples(src)
debug_script(testsrc, pm, globs)
@@ -2873,7 +2875,7 @@ __test__ = {"_TestClass": _TestClass,
def _test():
import argparse
parser = argparse.ArgumentParser(description="doctest runner")
parser = argparse.ArgumentParser(description="doctest runner", color=True)
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='print very verbose output for all tests')
parser.add_argument('-o', '--option', action='append',
+1249 -1407
View File
File diff suppressed because it is too large. Load diff