From 841d9022197c034f9942463d3467a7bb5974f019 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Thu, 20 Feb 2025 16:34:33 -0500 Subject: [PATCH] Add unit test --- test/unit/test_cli.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/unit/test_cli.py b/test/unit/test_cli.py index bf5e98ba..7828b188 100644 --- a/test/unit/test_cli.py +++ b/test/unit/test_cli.py @@ -6,7 +6,7 @@ from ansible_builder import constants from ansible_builder.main import AnsibleBuilder -from ansible_builder.cli import parse_args +from ansible_builder.cli import parse_args, _should_disable_colors from ansible_builder.policies import PolicyChoices @@ -390,3 +390,31 @@ def test_extra_build_cli_args(exec_env_definition_file, tmp_path): for extra in extras: assert extra in aee.build_command + + +@pytest.fixture +def env_save(): + orig = {} + for val in ('NO_COLOR', 'FORCE_COLOR', 'TERM'): + orig[val] = os.environ.get(val, None) + yield + for key, value in orig.items(): + if value: + os.environ[key] = value + + +@pytest.mark.parametrize('no_color,force_color,term,expected', + [ + ('', '', 'xterm', False), + ('1', '', 'xterm', True), + ('', '1', 'xterm', False), + ('1', '1', 'xterm', False), + ('', '', 'dumb', True), + ('', '1', 'dumb', True), + ]) +def test__should_disable_colors(no_color, force_color, term, expected, env_save): + # pylint: disable=W0613,W0621 + os.environ['NO_COLOR'] = no_color + os.environ['FORCE_COLOR'] = force_color + os.environ['TERM'] = term + assert _should_disable_colors() == expected