Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2c1108b
Add colour to doctest output and create _colorize module
hugovk Apr 6, 2024
d27c0a8
Use _colorize in traceback module
hugovk Apr 6, 2024
bb591b6
Fix whitespace
hugovk Apr 6, 2024
42079be
Use f-strings
hugovk Apr 6, 2024
0088579
Remove underscores from members of an underscored module
hugovk Apr 6, 2024
d3034fa
Add blurb
hugovk Apr 6, 2024
39780cb
Remove underscores from members of an underscored module
hugovk Apr 6, 2024
c5aec15
Revert "Fix whitespace"
hugovk Apr 6, 2024
7e40133
Move _colorize to stdlib block, colour->color
hugovk Apr 6, 2024
e484465
Move imports together
hugovk Apr 6, 2024
1c7b025
Move imports together
hugovk Apr 6, 2024
ab2c94c
Move imports together
hugovk Apr 6, 2024
1aaeab8
Revert notests -> no_tests
hugovk Apr 6, 2024
cd02e4a
Revert "Use f-strings"
hugovk Apr 6, 2024
06543ff
Fix local tests
hugovk Apr 6, 2024
31c6647
Use red divider for failed test
hugovk Apr 7, 2024
9be3d81
Fix local tests
hugovk Apr 7, 2024
e4ff3e3
Less red
hugovk Apr 7, 2024
b62500a
Revert unnecessary changes
hugovk Apr 7, 2024
eb4f8dc
Move colour tests to test__colorize.py
hugovk Apr 7, 2024
976bfb4
Refactor asserts
hugovk Apr 7, 2024
ad7a946
Add missing captured_output to test.support's __all__ to fix IDE warning
hugovk Apr 7, 2024
796e9f2
Only move test_colorized_detection_checks_for_environment_variables f…
hugovk Apr 7, 2024
99d4d0c
Apply suggestions from code review
hugovk Apr 7, 2024
95b9831
Use unittest's enterContext
hugovk Apr 7, 2024
d5417b4
Merge remote-tracking branch 'upstream/main' into doctest-tidy-output…
hugovk Apr 16, 2024
ece3ce0
Keep colorize functionality in traceback module for now
hugovk Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use unittest's enterContext
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
hugovk and AlexWaygood committed Apr 7, 2024
commit 95b983134099aa29f00d9cf3ffe9690e2fd1ece8
34 changes: 15 additions & 19 deletions Lib/test/test__colorize.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import contextlib
import sys
import traceback
import unittest
import unittest.mock
import _colorize
from test.support import captured_output


class TestColorizeFunction(unittest.TestCase):
def test_colorized_detection_checks_for_environment_variables(self):
Comment thread
AlexWaygood marked this conversation as resolved.
Outdated
if sys.platform == "win32":
virtual_patching = unittest.mock.patch(
"nt._supports_virtual_terminal", return_value=True
)
else:
virtual_patching = contextlib.nullcontext()

env_vars_expected = [
({'TERM': 'dumb'}, False),
({'PYTHON_COLORS': '1'}, True),
Expand All @@ -27,17 +17,23 @@ def test_colorized_detection_checks_for_environment_variables(self):
({'FORCE_COLOR': '1', "PYTHON_COLORS": '0'}, False),
]

with virtual_patching:
with unittest.mock.patch("os.isatty") as isatty_mock:
isatty_mock.return_value = True
if sys.platform == "win32":
self.enterContext(
unittest.mock.patch(
"nt._supports_virtual_terminal", return_value=True
)
)

isatty_mock = self.enterContext(unittest.mock.patch("os.isatty"))
isatty_mock.return_value = True

for env_vars, expected in env_vars_expected:
with self.subTest(env_vars=env_vars, expected_color=expected):
with unittest.mock.patch("os.environ", env_vars):
self.assertEqual(_colorize.can_colorize(), expected)
for env_vars, expected in env_vars_expected:
with self.subTest(env_vars=env_vars, expected_color=expected):
with unittest.mock.patch("os.environ", env_vars):
self.assertEqual(_colorize.can_colorize(), expected)

isatty_mock.return_value = False
self.assertEqual(_colorize.can_colorize(), False)
isatty_mock.return_value = False
self.assertEqual(_colorize.can_colorize(), False)


if __name__ == "__main__":
Expand Down