Skip to content
Merged
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion Lib/test/test__colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def setUpModule():
_colorize.can_colorize = lambda: False
_colorize.can_colorize = lambda *args, **kwargs: False


def tearDownModule():
Expand All @@ -21,6 +21,7 @@ class TestColorizeFunction(unittest.TestCase):
def test_colorized_detection_checks_for_environment_variables(self):
flags = unittest.mock.MagicMock(ignore_environment=False)
with (unittest.mock.patch("os.isatty") as isatty_mock,
unittest.mock.patch("sys.stdout") as stdout_mock,
unittest.mock.patch("sys.stderr") as stderr_mock,
unittest.mock.patch("sys.flags", flags),
unittest.mock.patch("_colorize.can_colorize", ORIGINAL_CAN_COLORIZE),
Expand All @@ -29,6 +30,8 @@ def test_colorized_detection_checks_for_environment_variables(self):
contextlib.nullcontext()) as vt_mock):

isatty_mock.return_value = True
stdout_mock.fileno.return_value = 1
stdout_mock.isatty.return_value = True
stderr_mock.fileno.return_value = 2
stderr_mock.isatty.return_value = True
with unittest.mock.patch("os.environ", {'TERM': 'dumb'}):
Expand Down Expand Up @@ -61,6 +64,7 @@ def test_colorized_detection_checks_for_environment_variables(self):
self.assertEqual(_colorize.can_colorize(), True)

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

Expand Down
Loading