diff options
author | Andrey Efremov <duxus@yandex.ru> | 2024-12-12 20:17:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-12 20:17:39 (GMT) |
commit | 365451e28368db46ae89a3a990d85c10c2284aa2 (patch) | |
tree | aed29e4790387fb03d52f5a49eed75f4fe8cb9ed /Lib/test | |
parent | f823910bbd4bf01ec3e1ab7b3cb1d77815138296 (diff) | |
download | cpython-365451e28368db46ae89a3a990d85c10c2284aa2.zip cpython-365451e28368db46ae89a3a990d85c10c2284aa2.tar.gz cpython-365451e28368db46ae89a3a990d85c10c2284aa2.tar.bz2 |
gh-127353: Allow to force color output on Windows (#127354)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test__colorize.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test__colorize.py b/Lib/test/test__colorize.py index d55b97a..7a65d63 100644 --- a/Lib/test/test__colorize.py +++ b/Lib/test/test__colorize.py @@ -50,10 +50,47 @@ class TestColorizeFunction(unittest.TestCase): with unittest.mock.patch("os.environ", {'FORCE_COLOR': '1', "PYTHON_COLORS": '0'}): self.assertEqual(_colorize.can_colorize(), False) + with unittest.mock.patch("os.environ", {}): + self.assertEqual(_colorize.can_colorize(), True) + isatty_mock.return_value = False with unittest.mock.patch("os.environ", {}): self.assertEqual(_colorize.can_colorize(), False) + @force_not_colorized + @unittest.skipUnless(sys.platform == "win32", "Windows only") + def test_colorized_detection_checks_for_environment_variables_no_vt(self): + with (unittest.mock.patch("nt._supports_virtual_terminal", return_value=False), + unittest.mock.patch("os.isatty") as isatty_mock, + unittest.mock.patch("sys.flags", unittest.mock.MagicMock(ignore_environment=False)), + unittest.mock.patch("_colorize.can_colorize", ORIGINAL_CAN_COLORIZE)): + isatty_mock.return_value = True + with unittest.mock.patch("os.environ", {'TERM': 'dumb'}): + self.assertEqual(_colorize.can_colorize(), False) + with unittest.mock.patch("os.environ", {'PYTHON_COLORS': '1'}): + self.assertEqual(_colorize.can_colorize(), True) + with unittest.mock.patch("os.environ", {'PYTHON_COLORS': '0'}): + self.assertEqual(_colorize.can_colorize(), False) + with unittest.mock.patch("os.environ", {'NO_COLOR': '1'}): + self.assertEqual(_colorize.can_colorize(), False) + with unittest.mock.patch("os.environ", + {'NO_COLOR': '1', "PYTHON_COLORS": '1'}): + self.assertEqual(_colorize.can_colorize(), True) + with unittest.mock.patch("os.environ", {'FORCE_COLOR': '1'}): + self.assertEqual(_colorize.can_colorize(), True) + with unittest.mock.patch("os.environ", + {'FORCE_COLOR': '1', 'NO_COLOR': '1'}): + self.assertEqual(_colorize.can_colorize(), False) + with unittest.mock.patch("os.environ", + {'FORCE_COLOR': '1', "PYTHON_COLORS": '0'}): + self.assertEqual(_colorize.can_colorize(), False) + with unittest.mock.patch("os.environ", {}): + self.assertEqual(_colorize.can_colorize(), False) + + isatty_mock.return_value = False + with unittest.mock.patch("os.environ", {}): + self.assertEqual(_colorize.can_colorize(), False) + if __name__ == "__main__": unittest.main() |