summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest
diff options
context:
space:
mode:
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>2024-05-01 18:27:06 (GMT)
committerGitHub <noreply@github.com>2024-05-01 18:27:06 (GMT)
commit3b3f8dea575d81a9e68f04b434942d06bd03fad5 (patch)
tree13ed08c5e83aa482167ea594997feda61f0ee545 /Lib/test/test_doctest
parent164e2c31c073b5fd8d25b3432a5e5c721f747393 (diff)
downloadcpython-3b3f8dea575d81a9e68f04b434942d06bd03fad5.zip
cpython-3b3f8dea575d81a9e68f04b434942d06bd03fad5.tar.gz
cpython-3b3f8dea575d81a9e68f04b434942d06bd03fad5.tar.bz2
gh-117225: Move colorize functionality to own internal module (#118283)
Diffstat (limited to 'Lib/test/test_doctest')
-rw-r--r--Lib/test/test_doctest/test_doctest.py56
1 files changed, 28 insertions, 28 deletions
diff --git a/Lib/test/test_doctest/test_doctest.py b/Lib/test/test_doctest/test_doctest.py
index 0f1e584..3a173e8 100644
--- a/Lib/test/test_doctest/test_doctest.py
+++ b/Lib/test/test_doctest/test_doctest.py
@@ -16,7 +16,7 @@ import unittest
import tempfile
import types
import contextlib
-import traceback
+import _colorize
def doctest_skip_if(condition):
@@ -893,8 +893,8 @@ Unit tests for the `DocTestRunner` class.
DocTestRunner is used to run DocTest test cases, and to accumulate
statistics. Here's a simple DocTest case we can use:
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> def f(x):
... '''
@@ -951,7 +951,7 @@ the failure and proceeds to the next example:
ok
TestResults(failed=1, attempted=3)
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
def verbose_flag(): r"""
The `verbose` flag makes the test runner generate more detailed
@@ -1027,8 +1027,8 @@ An expected exception is specified with a traceback message. The
lines between the first line and the type/value may be omitted or
replaced with any other string:
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> def f(x):
... '''
@@ -1261,7 +1261,7 @@ unexpected exception:
ZeroDivisionError: integer division or modulo by zero
TestResults(failed=1, attempted=1)
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
def displayhook(): r"""
Test that changing sys.displayhook doesn't matter for doctest.
@@ -1303,8 +1303,8 @@ together).
The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False
and 1/0:
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> def f(x):
... '>>> True\n1\n'
@@ -1725,7 +1725,7 @@ more than one flag value. Here we verify that's fixed:
Clean up.
>>> del doctest.OPTIONFLAGS_BY_NAME[unlikely]
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
@@ -1736,8 +1736,8 @@ 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
example with a comment of the form ``# doctest: +OPTION``:
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> def f(x): r'''
... >>> print(list(range(10))) # should fail: no ellipsis
@@ -1947,7 +1947,7 @@ source:
Traceback (most recent call last):
ValueError: line 0 of the doctest for s has an option directive on a line with no example: '# doctest: +ELLIPSIS'
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
def test_testsource(): r"""
@@ -2031,8 +2031,8 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
with a version that restores stdout. This is necessary for you to
see debugger output.
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> doc = '''
... >>> x = 42
@@ -2157,7 +2157,7 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
9
TestResults(failed=1, attempted=3)
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
def test_pdb_set_trace_nested():
@@ -2694,8 +2694,8 @@ calling module. The return value is (#failures, #tests).
We don't want color or `-v` in sys.argv for these tests.
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> save_argv = sys.argv
>>> if '-v' in sys.argv:
@@ -2863,7 +2863,7 @@ Test the verbose output:
TestResults(failed=0, attempted=2)
>>> doctest.master = None # Reset master.
>>> sys.argv = save_argv
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
class TestImporter(importlib.abc.MetaPathFinder, importlib.abc.ResourceLoader):
@@ -3001,8 +3001,8 @@ if supports_unicode:
def test_unicode(): """
Check doctest with a non-ascii filename:
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> doc = '''
... >>> raise Exception('clé')
@@ -3030,7 +3030,7 @@ Check doctest with a non-ascii filename:
Exception: clé
TestResults(failed=1, attempted=1)
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
@@ -3325,8 +3325,8 @@ def test_run_doctestsuite_multiple_times():
def test_exception_with_note(note):
"""
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> test_exception_with_note('Note')
Traceback (most recent call last):
@@ -3378,7 +3378,7 @@ def test_exception_with_note(note):
note
TestResults(failed=1, attempted=...)
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""
exc = ValueError('Text')
exc.add_note(note)
@@ -3459,8 +3459,8 @@ def test_syntax_error_subclass_from_stdlib():
def test_syntax_error_with_incorrect_expected_note():
"""
- >>> save_colorize = traceback._COLORIZE
- >>> traceback._COLORIZE = False
+ >>> save_colorize = _colorize.COLORIZE
+ >>> _colorize.COLORIZE = False
>>> def f(x):
... r'''
@@ -3491,7 +3491,7 @@ def test_syntax_error_with_incorrect_expected_note():
note2
TestResults(failed=1, attempted=...)
- >>> traceback._COLORIZE = save_colorize
+ >>> _colorize.COLORIZE = save_colorize
"""