mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
gh-120417: Move imports to doctests in test_doctest (#120679)
This commit is contained in:
parent
02b272b702
commit
d2e423114c
1 changed files with 14 additions and 4 deletions
|
@ -4,7 +4,6 @@ Test script for doctest.
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
from test.support.pty_helper import FakeInput # used in doctests
|
|
||||||
import doctest
|
import doctest
|
||||||
import functools
|
import functools
|
||||||
import os
|
import os
|
||||||
|
@ -16,7 +15,6 @@ import unittest
|
||||||
import tempfile
|
import tempfile
|
||||||
import types
|
import types
|
||||||
import contextlib
|
import contextlib
|
||||||
import _colorize
|
|
||||||
|
|
||||||
|
|
||||||
def doctest_skip_if(condition):
|
def doctest_skip_if(condition):
|
||||||
|
@ -471,7 +469,7 @@ We'll simulate a __file__ attr that ends in pyc:
|
||||||
>>> tests = finder.find(sample_func)
|
>>> tests = finder.find(sample_func)
|
||||||
|
|
||||||
>>> print(tests) # doctest: +ELLIPSIS
|
>>> print(tests) # doctest: +ELLIPSIS
|
||||||
[<DocTest sample_func from test_doctest.py:38 (1 example)>]
|
[<DocTest sample_func from test_doctest.py:36 (1 example)>]
|
||||||
|
|
||||||
The exact name depends on how test_doctest was invoked, so allow for
|
The exact name depends on how test_doctest was invoked, so allow for
|
||||||
leading path components.
|
leading path components.
|
||||||
|
@ -893,6 +891,7 @@ Unit tests for the `DocTestRunner` class.
|
||||||
DocTestRunner is used to run DocTest test cases, and to accumulate
|
DocTestRunner is used to run DocTest test cases, and to accumulate
|
||||||
statistics. Here's a simple DocTest case we can use:
|
statistics. Here's a simple DocTest case we can use:
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -1027,6 +1026,7 @@ An expected exception is specified with a traceback message. The
|
||||||
lines between the first line and the type/value may be omitted or
|
lines between the first line and the type/value may be omitted or
|
||||||
replaced with any other string:
|
replaced with any other string:
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -1303,6 +1303,7 @@ together).
|
||||||
The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False
|
The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False
|
||||||
and 1/0:
|
and 1/0:
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -1736,6 +1737,7 @@ Option directives can be used to turn option flags on or off for a
|
||||||
single example. To turn an option on for an example, follow that
|
single example. To turn an option on for an example, follow that
|
||||||
example with a comment of the form ``# doctest: +OPTION``:
|
example with a comment of the form ``# doctest: +OPTION``:
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -2002,6 +2004,7 @@ Create a docstring that we want to debug:
|
||||||
|
|
||||||
Create some fake stdin input, to feed to the debugger:
|
Create some fake stdin input, to feed to the debugger:
|
||||||
|
|
||||||
|
>>> from test.support.pty_helper import FakeInput
|
||||||
>>> real_stdin = sys.stdin
|
>>> real_stdin = sys.stdin
|
||||||
>>> sys.stdin = FakeInput(['next', 'print(x)', 'continue'])
|
>>> sys.stdin = FakeInput(['next', 'print(x)', 'continue'])
|
||||||
|
|
||||||
|
@ -2031,6 +2034,7 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
|
||||||
with a version that restores stdout. This is necessary for you to
|
with a version that restores stdout. This is necessary for you to
|
||||||
see debugger output.
|
see debugger output.
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -2048,6 +2052,7 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
|
||||||
To demonstrate this, we'll create a fake standard input that
|
To demonstrate this, we'll create a fake standard input that
|
||||||
captures our debugger input:
|
captures our debugger input:
|
||||||
|
|
||||||
|
>>> from test.support.pty_helper import FakeInput
|
||||||
>>> real_stdin = sys.stdin
|
>>> real_stdin = sys.stdin
|
||||||
>>> sys.stdin = FakeInput([
|
>>> sys.stdin = FakeInput([
|
||||||
... 'print(x)', # print data defined by the example
|
... 'print(x)', # print data defined by the example
|
||||||
|
@ -2086,7 +2091,7 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
|
||||||
... runner.run(test)
|
... runner.run(test)
|
||||||
... finally:
|
... finally:
|
||||||
... sys.stdin = real_stdin
|
... sys.stdin = real_stdin
|
||||||
> <doctest test.test_doctest.test_doctest.test_pdb_set_trace[9]>(3)calls_set_trace()
|
> <doctest test.test_doctest.test_doctest.test_pdb_set_trace[11]>(3)calls_set_trace()
|
||||||
-> import pdb; pdb.set_trace()
|
-> import pdb; pdb.set_trace()
|
||||||
(Pdb) print(y)
|
(Pdb) print(y)
|
||||||
2
|
2
|
||||||
|
@ -2188,6 +2193,7 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
|
||||||
>>> parser = doctest.DocTestParser()
|
>>> parser = doctest.DocTestParser()
|
||||||
>>> runner = doctest.DocTestRunner(verbose=False)
|
>>> runner = doctest.DocTestRunner(verbose=False)
|
||||||
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
|
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
|
||||||
|
>>> from test.support.pty_helper import FakeInput
|
||||||
>>> real_stdin = sys.stdin
|
>>> real_stdin = sys.stdin
|
||||||
>>> sys.stdin = FakeInput([
|
>>> sys.stdin = FakeInput([
|
||||||
... 'step',
|
... 'step',
|
||||||
|
@ -2700,6 +2706,7 @@ calling module. The return value is (#failures, #tests).
|
||||||
|
|
||||||
We don't want color or `-v` in sys.argv for these tests.
|
We don't want color or `-v` in sys.argv for these tests.
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -3007,6 +3014,7 @@ if supports_unicode:
|
||||||
def test_unicode(): """
|
def test_unicode(): """
|
||||||
Check doctest with a non-ascii filename:
|
Check doctest with a non-ascii filename:
|
||||||
|
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -3331,6 +3339,7 @@ def test_run_doctestsuite_multiple_times():
|
||||||
|
|
||||||
def test_exception_with_note(note):
|
def test_exception_with_note(note):
|
||||||
"""
|
"""
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
@ -3465,6 +3474,7 @@ def test_syntax_error_subclass_from_stdlib():
|
||||||
|
|
||||||
def test_syntax_error_with_incorrect_expected_note():
|
def test_syntax_error_with_incorrect_expected_note():
|
||||||
"""
|
"""
|
||||||
|
>>> import _colorize
|
||||||
>>> save_colorize = _colorize.COLORIZE
|
>>> save_colorize = _colorize.COLORIZE
|
||||||
>>> _colorize.COLORIZE = False
|
>>> _colorize.COLORIZE = False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue