from test import support
from test.support import import_helper
-from test.support.pty_helper import FakeInput # used in doctests
import doctest
import functools
import os
import tempfile
import types
import contextlib
-import _colorize
def doctest_skip_if(condition):
>>> tests = finder.find(sample_func)
>>> 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
leading path components.
DocTestRunner is used to run DocTest test cases, and to accumulate
statistics. Here's a simple DocTest case we can use:
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
lines between the first line and the type/value may be omitted or
replaced with any other string:
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False
and 1/0:
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
single example. To turn an option on for an example, follow that
example with a comment of the form ``# doctest: +OPTION``:
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
Create some fake stdin input, to feed to the debugger:
+ >>> from test.support.pty_helper import FakeInput
>>> real_stdin = sys.stdin
>>> sys.stdin = FakeInput(['next', 'print(x)', 'continue'])
with a version that restores stdout. This is necessary for you to
see debugger output.
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
To demonstrate this, we'll create a fake standard input that
captures our debugger input:
+ >>> from test.support.pty_helper import FakeInput
>>> real_stdin = sys.stdin
>>> sys.stdin = FakeInput([
... 'print(x)', # print data defined by the example
... runner.run(test)
... finally:
... 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()
(Pdb) print(y)
2
>>> parser = doctest.DocTestParser()
>>> runner = doctest.DocTestRunner(verbose=False)
>>> 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
>>> sys.stdin = FakeInput([
... 'step',
We don't want color or `-v` in sys.argv for these tests.
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
def test_unicode(): """
Check doctest with a non-ascii filename:
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
def test_exception_with_note(note):
"""
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
def test_syntax_error_with_incorrect_expected_note():
"""
+ >>> import _colorize
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False