Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Apr 16, 2024
1 parent d5417b4 commit 7dd21c9
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 173 deletions.
45 changes: 0 additions & 45 deletions Lib/_colorize.py

This file was deleted.

25 changes: 12 additions & 13 deletions Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def _test():
import unittest
from io import StringIO, IncrementalNewlineDecoder
from collections import namedtuple
import _colorize # Used in doctests
from _colorize import ANSIColors, can_colorize
from traceback import _ANSIColors, _can_colorize


class TestResults(namedtuple('TestResults', 'failed attempted')):
Expand Down Expand Up @@ -1181,8 +1180,8 @@ class DocTestRunner:
The `run` method is used to process a single DocTest case. It
returns a TestResults instance.
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> tests = DocTestFinder().find(_TestClass)
>>> runner = DocTestRunner(verbose=False)
Expand Down Expand Up @@ -1235,7 +1234,7 @@ class DocTestRunner:
overriding the methods `report_start`, `report_success`,
`report_unexpected_exception`, and `report_failure`.
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""
# This divider string is used to separate failure messages, and to
# separate sections of the summary.
Expand Down Expand Up @@ -1315,7 +1314,7 @@ def report_unexpected_exception(self, out, test, example, exc_info):

def _failure_header(self, test, example):
red, reset = (
(ANSIColors.RED, ANSIColors.RESET) if can_colorize() else ("", "")
(_ANSIColors.RED, _ANSIColors.RESET) if _can_colorize() else ("", "")
)
out = [f"{red}{self.DIVIDER}{reset}"]
if test.filename:
Expand Down Expand Up @@ -1602,13 +1601,13 @@ def summarize(self, verbose=None):
else:
failed.append((name, (failures, tries, skips)))

if can_colorize():
bold_green = ANSIColors.BOLD_GREEN
bold_red = ANSIColors.BOLD_RED
green = ANSIColors.GREEN
red = ANSIColors.RED
reset = ANSIColors.RESET
yellow = ANSIColors.YELLOW
if _can_colorize():
bold_green = _ANSIColors.BOLD_GREEN
bold_red = _ANSIColors.BOLD_RED
green = _ANSIColors.GREEN
red = _ANSIColors.RED
reset = _ANSIColors.RESET
yellow = _ANSIColors.YELLOW
else:
bold_green = ""
bold_red = ""
Expand Down
40 changes: 0 additions & 40 deletions Lib/test/test__colorize.py

This file was deleted.

58 changes: 29 additions & 29 deletions Lib/test/test_doctest/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import tempfile
import types
import contextlib
import _colorize # used in doctests
import traceback


def doctest_skip_if(condition):
Expand Down Expand Up @@ -471,7 +471,7 @@ def basics(): r"""
>>> tests = finder.find(sample_func)
>>> print(tests) # doctest: +ELLIPSIS
[<DocTest sample_func from test_doctest.py:37 (1 example)>]
[<DocTest sample_func from test_doctest.py:38 (1 example)>]
The exact name depends on how test_doctest was invoked, so allow for
leading path components.
Expand Down Expand Up @@ -893,8 +893,8 @@ def basics(): r"""
DocTestRunner is used to run DocTest test cases, and to accumulate
statistics. Here's a simple DocTest case we can use:
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> def f(x):
... '''
Expand Down Expand Up @@ -951,7 +951,7 @@ def basics(): r"""
ok
TestResults(failed=1, attempted=3)
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""
def verbose_flag(): r"""
The `verbose` flag makes the test runner generate more detailed
Expand Down Expand Up @@ -1027,8 +1027,8 @@ def exceptions(): r"""
lines between the first line and the type/value may be omitted or
replaced with any other string:
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> def f(x):
... '''
Expand Down Expand Up @@ -1261,7 +1261,7 @@ def exceptions(): r"""
ZeroDivisionError: integer division or modulo by zero
TestResults(failed=1, attempted=1)
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""
def displayhook(): r"""
Test that changing sys.displayhook doesn't matter for doctest.
Expand Down Expand Up @@ -1303,8 +1303,8 @@ def optionflags(): r"""
The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False
and 1/0:
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> def f(x):
... '>>> True\n1\n'
Expand Down Expand Up @@ -1725,7 +1725,7 @@ def optionflags(): r"""
Clean up.
>>> del doctest.OPTIONFLAGS_BY_NAME[unlikely]
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""

Expand All @@ -1736,8 +1736,8 @@ def option_directives(): r"""
single example. To turn an option on for an example, follow that
example with a comment of the form ``# doctest: +OPTION``:
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> def f(x): r'''
... >>> print(list(range(10))) # should fail: no ellipsis
Expand Down Expand Up @@ -1947,7 +1947,7 @@ def option_directives(): r"""
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'
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""

def test_testsource(): r"""
Expand Down Expand Up @@ -2031,8 +2031,8 @@ def test_pdb_set_trace():
with a version that restores stdout. This is necessary for you to
see debugger output.
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> doc = '''
... >>> x = 42
Expand Down Expand Up @@ -2157,7 +2157,7 @@ def test_pdb_set_trace():
9
TestResults(failed=1, attempted=3)
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""

def test_pdb_set_trace_nested():
Expand Down Expand Up @@ -2679,8 +2679,8 @@ def test_testfile(): r"""
We don't want color or `-v` in sys.argv for these tests.
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> save_argv = sys.argv
>>> if '-v' in sys.argv:
Expand Down Expand Up @@ -2848,7 +2848,7 @@ def test_testfile(): r"""
TestResults(failed=0, attempted=2)
>>> doctest.master = None # Reset master.
>>> sys.argv = save_argv
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""

class TestImporter(importlib.abc.MetaPathFinder, importlib.abc.ResourceLoader):
Expand Down Expand Up @@ -2986,8 +2986,8 @@ def test_testmod(): r"""
def test_unicode(): """
Check doctest with a non-ascii filename:
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> doc = '''
... >>> raise Exception('clé')
Expand Down Expand Up @@ -3015,7 +3015,7 @@ def test_unicode(): """
Exception: clé
TestResults(failed=1, attempted=1)
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""


Expand Down Expand Up @@ -3310,8 +3310,8 @@ def test_run_doctestsuite_multiple_times():

def test_exception_with_note(note):
"""
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> test_exception_with_note('Note')
Traceback (most recent call last):
Expand Down Expand Up @@ -3363,7 +3363,7 @@ def test_exception_with_note(note):
note
TestResults(failed=1, attempted=...)
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""
exc = ValueError('Text')
exc.add_note(note)
Expand Down Expand Up @@ -3444,8 +3444,8 @@ def test_syntax_error_subclass_from_stdlib():

def test_syntax_error_with_incorrect_expected_note():
"""
>>> save_colorize = _colorize.COLORIZE
>>> _colorize.COLORIZE = False
>>> save_colorize = traceback._COLORIZE
>>> traceback._COLORIZE = False
>>> def f(x):
... r'''
Expand Down Expand Up @@ -3476,7 +3476,7 @@ def test_syntax_error_with_incorrect_expected_note():
note2
TestResults(failed=1, attempted=...)
>>> _colorize.COLORIZE = save_colorize
>>> traceback._COLORIZE = save_colorize
"""


Expand Down
Loading

0 comments on commit 7dd21c9

Please sign in to comment.