From 41ff2f57ec0a15ff1630e89afa47e835c274d3ed Mon Sep 17 00:00:00 2001 From: Mick Koch Date: Thu, 4 Jun 2020 20:53:58 -0400 Subject: [PATCH 1/3] Add tests for current colorama_initialize logic --- .../unittests/client/conan_output_test.py | 106 +++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/conans/test/unittests/client/conan_output_test.py b/conans/test/unittests/client/conan_output_test.py index 77838157ce0..e5f220da03e 100644 --- a/conans/test/unittests/client/conan_output_test.py +++ b/conans/test/unittests/client/conan_output_test.py @@ -5,7 +5,7 @@ from six import StringIO -from conans.client.output import ConanOutput +from conans.client.output import ConanOutput, colorama_initialize from mock import mock @@ -28,3 +28,107 @@ def write_raise(self, data): out.write("Hello world") sleep.assert_any_call(0.02) self.assertEqual("Hello world", stream.getvalue()) + + def test_output_color(self): + # Output is not a terminal, no overrides. + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = False + env = {} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, no overrides. + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with() + + # Output is not a terminal, prevent color generation (CONAN_COLOR_DISPLAY=0). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = False + env = {"CONAN_COLOR_DISPLAY": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, prevent color generation (CONAN_COLOR_DISPLAY=0). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CONAN_COLOR_DISPLAY": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is not a terminal, force color generation (CONAN_COLOR_DISPLAY=1). + # Color generation enabled, colorama will strip colors. + with mock.patch("colorama.init") as init: + isatty = False + env = {"CONAN_COLOR_DISPLAY": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with() + + # Output is a terminal, force color generation (CONAN_COLOR_DISPLAY=1). + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CONAN_COLOR_DISPLAY": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with() + + # Output is not a terminal, no forced color generation, prevent color stripping + # (PYCHARM_HOSTED=1). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = False + env = {"PYCHARM_HOSTED": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is not a terminal, force color generation (CONAN_COLOR_DISPLAY=1), + # prevent color stripping (PYCHARM_HOSTED=1). + # Color generation enabled, colorama will not strip colors (forced). + with mock.patch("colorama.init") as init: + isatty = False + env = {"PYCHARM_HOSTED": "1", "CONAN_COLOR_DISPLAY": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with(convert=False, strip=False) + + # Output is a terminal, prevent color generation (CONAN_COLOR_DISPLAY=0), prevent + # color stripping (PYCHARM_HOSTED=1). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = True + env = {"PYCHARM_HOSTED": "1", "CONAN_COLOR_DISPLAY": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, prevent color stripping (PYCHARM_HOSTED=1). + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {"PYCHARM_HOSTED": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with(convert=False, strip=False) From 89b5caf92b93cc4d91a48e47db9c0bd3d8dc6c5d Mon Sep 17 00:00:00 2001 From: Mick Koch Date: Thu, 4 Jun 2020 22:15:45 -0400 Subject: [PATCH 2/3] Add support for CLICOLOR/CLICOLOR_FORCE/NO_COLOR output controls These are checked in addition to the current color control variables. The CLICOLOR/CLICOLOR_FORCE variables are implemented according to https://bixense.com/clicolors/ The NO_COLOR variable is implemented according to https://no-color.org/ The colorization behavior falls back to the original logic if these variables are unset or if CLICOLOR_FORCE=0. --- conans/client/output.py | 23 +++- .../unittests/client/conan_output_test.py | 127 ++++++++++++++++++ 2 files changed, 147 insertions(+), 3 deletions(-) diff --git a/conans/client/output.py b/conans/client/output.py index b36fb06d153..882754ef7c5 100644 --- a/conans/client/output.py +++ b/conans/client/output.py @@ -8,12 +8,29 @@ def colorama_initialize(): + if "NO_COLOR" in os.environ: + return False + + clicolor_force = get_env("CLICOLOR_FORCE") + if clicolor_force is not None and clicolor_force != "0": + import colorama + colorama.init(convert=False, strip=False) + return True + + isatty = hasattr(sys.stdout, "isatty") and sys.stdout.isatty() + + clicolor = get_env("CLICOLOR") + if clicolor is not None: + if clicolor == "0" or not isatty: + return False + import colorama + colorama.init() + return True + # Respect color env setting or check tty if unset color_set = "CONAN_COLOR_DISPLAY" in os.environ if ((color_set and get_env("CONAN_COLOR_DISPLAY", 1)) - or (not color_set - and hasattr(sys.stdout, "isatty") - and sys.stdout.isatty())): + or (not color_set and isatty)): import colorama if get_env("PYCHARM_HOSTED"): # in PyCharm disable convert/strip colorama.init(convert=False, strip=False) diff --git a/conans/test/unittests/client/conan_output_test.py b/conans/test/unittests/client/conan_output_test.py index e5f220da03e..613f620fa3e 100644 --- a/conans/test/unittests/client/conan_output_test.py +++ b/conans/test/unittests/client/conan_output_test.py @@ -30,6 +30,10 @@ def write_raise(self, data): self.assertEqual("Hello world", stream.getvalue()) def test_output_color(self): + ######################################################### + # Color control with CONAN_COLOR_DISPLAY/PYCHARM_HOSTED # + ######################################################### + # Output is not a terminal, no overrides. # Color generation disabled. with mock.patch("colorama.init") as init: @@ -132,3 +136,126 @@ def test_output_color(self): mock.patch.dict("os.environ", env, clear=True): assert colorama_initialize() init.assert_called_once_with(convert=False, strip=False) + + ####################################################### + # Color control with CLICOLOR/CLICOLOR_FORCE/NO_COLOR # + ####################################################### + + # Output is a terminal, prevent color generation (NO_COLOR). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = True + env = {"NO_COLOR": ""} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, prevent color generation (CLICOLOR=0). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CLICOLOR": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, prevent color generation (CLICOLOR=0), override + # CONAN_COLOR_DISPLAY=1. + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CLICOLOR": "0", "CONAN_COLOR_DISPLAY": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, request color generation (CLICOLOR=1). + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CLICOLOR": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with() + + # Output is not a terminal, request color generation (CLICOLOR=1). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = False + env = {"CLICOLOR": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is not a terminal, force color generation (CLICOLOR_FORCE=1), + # prevent color stripping (CLICOLOR_FORCE=1). + # Color generation enabled, colorama will not strip colors (forced). + with mock.patch("colorama.init") as init: + isatty = False + env = {"CLICOLOR_FORCE": "1"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with(convert=False, strip=False) + + # Output is a terminal, force enable color generation (CLICOLOR_FORCE=1), + # override CLICOLOR=0, prevent color stripping (CLICOLOR_FORCE=1). + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CLICOLOR_FORCE": "1", "CLICOLOR": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with(convert=False, strip=False) + + # Output is a terminal, force enable color generation (CLICOLOR_FORCE=1), + # override CONAN_COLOR_DISPLAY=0, prevent color stripping (CLICOLOR_FORCE=1). + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CLICOLOR_FORCE": "1", "CONAN_COLOR_DISPLAY": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with(convert=False, strip=False) + + # Output is not a terminal, disable forced color generation (CLICOLOR_FORCE=0). + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = False + env = {"CLICOLOR_FORCE": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() + + # Output is a terminal, disable forced color generation (CLICOLOR_FORCE=0). + # Color generation enabled, colorama will not strip colors. + with mock.patch("colorama.init") as init: + isatty = True + env = {"CLICOLOR_FORCE": "0"} + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert colorama_initialize() + init.assert_called_once_with() + + # Output is a terminal, prevent color generation (NO_COLOR), overriding other + # controls. + # Color generation disabled. + with mock.patch("colorama.init") as init: + isatty = True + env = { + "CLICOLOR": "1", "CLICOLOR_FORCE": "1", + "CONAN_COLOR_DISPLAY": "1", "PYCHARM_HOSTED": "1", + "NO_COLOR": "1" + } + with mock.patch("sys.stdout.isatty", return_value=isatty), \ + mock.patch.dict("os.environ", env, clear=True): + assert not colorama_initialize() + init.assert_not_called() From e67c01ae59f7f385f69807ee70761295abdc537a Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 30 Jun 2020 14:21:59 +0200 Subject: [PATCH 3/3] refactor tests --- .../unittests/client/conan_output_test.py | 240 ++---------------- 1 file changed, 27 insertions(+), 213 deletions(-) diff --git a/conans/test/unittests/client/conan_output_test.py b/conans/test/unittests/client/conan_output_test.py index 613f620fa3e..26dc205817b 100644 --- a/conans/test/unittests/client/conan_output_test.py +++ b/conans/test/unittests/client/conan_output_test.py @@ -3,6 +3,7 @@ import unittest from types import MethodType +from parameterized import parameterized from six import StringIO from conans.client.output import ConanOutput, colorama_initialize @@ -29,233 +30,46 @@ def write_raise(self, data): sleep.assert_any_call(0.02) self.assertEqual("Hello world", stream.getvalue()) - def test_output_color(self): - ######################################################### - # Color control with CONAN_COLOR_DISPLAY/PYCHARM_HOSTED # - ######################################################### - - # Output is not a terminal, no overrides. - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = False - env = {} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is a terminal, no overrides. - # Color generation enabled, colorama will not strip colors. - with mock.patch("colorama.init") as init: - isatty = True - env = {} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with() - - # Output is not a terminal, prevent color generation (CONAN_COLOR_DISPLAY=0). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = False - env = {"CONAN_COLOR_DISPLAY": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is a terminal, prevent color generation (CONAN_COLOR_DISPLAY=0). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CONAN_COLOR_DISPLAY": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is not a terminal, force color generation (CONAN_COLOR_DISPLAY=1). - # Color generation enabled, colorama will strip colors. - with mock.patch("colorama.init") as init: - isatty = False - env = {"CONAN_COLOR_DISPLAY": "1"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with() - - # Output is a terminal, force color generation (CONAN_COLOR_DISPLAY=1). - # Color generation enabled, colorama will not strip colors. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CONAN_COLOR_DISPLAY": "1"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with() - - # Output is not a terminal, no forced color generation, prevent color stripping - # (PYCHARM_HOSTED=1). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = False - env = {"PYCHARM_HOSTED": "1"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is not a terminal, force color generation (CONAN_COLOR_DISPLAY=1), - # prevent color stripping (PYCHARM_HOSTED=1). - # Color generation enabled, colorama will not strip colors (forced). - with mock.patch("colorama.init") as init: - isatty = False - env = {"PYCHARM_HOSTED": "1", "CONAN_COLOR_DISPLAY": "1"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with(convert=False, strip=False) - - # Output is a terminal, prevent color generation (CONAN_COLOR_DISPLAY=0), prevent - # color stripping (PYCHARM_HOSTED=1). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = True - env = {"PYCHARM_HOSTED": "1", "CONAN_COLOR_DISPLAY": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is a terminal, prevent color stripping (PYCHARM_HOSTED=1). - # Color generation enabled, colorama will not strip colors. + @parameterized.expand([(False, {}), + (False, {"CONAN_COLOR_DISPLAY": "0"}), + (True, {"CONAN_COLOR_DISPLAY": "0"}), + (False, {"PYCHARM_HOSTED": "1"}), + (True, {"PYCHARM_HOSTED": "1", "CONAN_COLOR_DISPLAY": "0"}), + (True, {"NO_COLOR": ""}), + (True, {"CLICOLOR": "0"}), + (True, {"CLICOLOR": "0", "CONAN_COLOR_DISPLAY": "1"}), + (False, {"CLICOLOR": "1"}), + (False, {"CLICOLOR_FORCE": "0"}), + (True, + {"CLICOLOR": "1", "CLICOLOR_FORCE": "1", "CONAN_COLOR_DISPLAY": "1", + "PYCHARM_HOSTED": "1", "NO_COLOR": "1"})]) + def test_output_no_color(self, isatty, env): with mock.patch("colorama.init") as init: - isatty = True - env = {"PYCHARM_HOSTED": "1"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with(convert=False, strip=False) - - ####################################################### - # Color control with CLICOLOR/CLICOLOR_FORCE/NO_COLOR # - ####################################################### - - # Output is a terminal, prevent color generation (NO_COLOR). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = True - env = {"NO_COLOR": ""} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is a terminal, prevent color generation (CLICOLOR=0). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CLICOLOR": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is a terminal, prevent color generation (CLICOLOR=0), override - # CONAN_COLOR_DISPLAY=1. - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CLICOLOR": "0", "CONAN_COLOR_DISPLAY": "1"} with mock.patch("sys.stdout.isatty", return_value=isatty), \ mock.patch.dict("os.environ", env, clear=True): assert not colorama_initialize() init.assert_not_called() - # Output is a terminal, request color generation (CLICOLOR=1). - # Color generation enabled, colorama will not strip colors. + @parameterized.expand([(True, {}), + (False, {"CONAN_COLOR_DISPLAY": "1"}), + (True, {"CONAN_COLOR_DISPLAY": "1"}), + (True, {"CLICOLOR": "1"}), + (True, {"CLICOLOR_FORCE": "0"})]) + def test_output_color(self, isatty, env): with mock.patch("colorama.init") as init: - isatty = True - env = {"CLICOLOR": "1"} with mock.patch("sys.stdout.isatty", return_value=isatty), \ mock.patch.dict("os.environ", env, clear=True): assert colorama_initialize() init.assert_called_once_with() - # Output is not a terminal, request color generation (CLICOLOR=1). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = False - env = {"CLICOLOR": "1"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is not a terminal, force color generation (CLICOLOR_FORCE=1), - # prevent color stripping (CLICOLOR_FORCE=1). - # Color generation enabled, colorama will not strip colors (forced). + @parameterized.expand([(False, {"PYCHARM_HOSTED": "1", "CONAN_COLOR_DISPLAY": "1"}), + (True, {"PYCHARM_HOSTED": "1"}), + (False, {"CLICOLOR_FORCE": "1"}), + (True, {"CLICOLOR_FORCE": "1", "CLICOLOR": "0"}), + (True, {"CLICOLOR_FORCE": "1", "CONAN_COLOR_DISPLAY": "0"})]) + def test_output_color_prevent_strip(self, isatty, env): with mock.patch("colorama.init") as init: - isatty = False - env = {"CLICOLOR_FORCE": "1"} with mock.patch("sys.stdout.isatty", return_value=isatty), \ mock.patch.dict("os.environ", env, clear=True): assert colorama_initialize() init.assert_called_once_with(convert=False, strip=False) - - # Output is a terminal, force enable color generation (CLICOLOR_FORCE=1), - # override CLICOLOR=0, prevent color stripping (CLICOLOR_FORCE=1). - # Color generation enabled, colorama will not strip colors. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CLICOLOR_FORCE": "1", "CLICOLOR": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with(convert=False, strip=False) - - # Output is a terminal, force enable color generation (CLICOLOR_FORCE=1), - # override CONAN_COLOR_DISPLAY=0, prevent color stripping (CLICOLOR_FORCE=1). - # Color generation enabled, colorama will not strip colors. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CLICOLOR_FORCE": "1", "CONAN_COLOR_DISPLAY": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with(convert=False, strip=False) - - # Output is not a terminal, disable forced color generation (CLICOLOR_FORCE=0). - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = False - env = {"CLICOLOR_FORCE": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called() - - # Output is a terminal, disable forced color generation (CLICOLOR_FORCE=0). - # Color generation enabled, colorama will not strip colors. - with mock.patch("colorama.init") as init: - isatty = True - env = {"CLICOLOR_FORCE": "0"} - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert colorama_initialize() - init.assert_called_once_with() - - # Output is a terminal, prevent color generation (NO_COLOR), overriding other - # controls. - # Color generation disabled. - with mock.patch("colorama.init") as init: - isatty = True - env = { - "CLICOLOR": "1", "CLICOLOR_FORCE": "1", - "CONAN_COLOR_DISPLAY": "1", "PYCHARM_HOSTED": "1", - "NO_COLOR": "1" - } - with mock.patch("sys.stdout.isatty", return_value=isatty), \ - mock.patch.dict("os.environ", env, clear=True): - assert not colorama_initialize() - init.assert_not_called()