From 458d157e629573e3a6f4dc78dcb14772765407f7 Mon Sep 17 00:00:00 2001 From: shivansh02 Date: Tue, 5 Mar 2024 00:15:52 +0530 Subject: [PATCH] NO_COLOR set to any value returns false --- borgmatic/logger.py | 2 +- tests/unit/test_logger.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/borgmatic/logger.py b/borgmatic/logger.py index d8f749c..8b7ffd5 100644 --- a/borgmatic/logger.py +++ b/borgmatic/logger.py @@ -42,7 +42,7 @@ def should_do_markup(no_color, configs): return False no_color_env = os.environ.get('NO_COLOR', None) - if no_color_env is not None and to_bool(no_color_env): + if no_color_env is not None: return False py_colors = os.environ.get('PY_COLORS', None) diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py index 505af68..6306a2e 100644 --- a/tests/unit/test_logger.py +++ b/tests/unit/test_logger.py @@ -69,7 +69,9 @@ def test_should_do_markup_prefers_any_false_config_value(): def test_should_do_markup_respects_PY_COLORS_environment_variable(): - flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return('True') + flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return( + 'True' + ) flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return(None) flexmock(module).should_receive('to_bool').and_return(True) @@ -109,30 +111,41 @@ def test_should_do_markup_respects_interactive_console_value(): def test_should_do_markup_prefers_PY_COLORS_to_interactive_console_value(): - flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return('True') + flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return( + 'True' + ) flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return(None) flexmock(module).should_receive('to_bool').and_return(True) flexmock(module).should_receive('interactive_console').and_return(False) assert module.should_do_markup(no_color=False, configs={}) is True + def test_should_do_markup_prefers_NO_COLOR_to_interactive_console_value(): flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return(None) flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('True') - flexmock(module).should_receive('to_bool').and_return(True) flexmock(module).should_receive('interactive_console').and_return(False) assert module.should_do_markup(no_color=False, configs={}) is False + def test_should_do_markup_respects_NO_COLOR_environment_variable(): flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('True') flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return(None) - - flexmock(module).should_receive('to_bool').and_return(True) assert module.should_do_markup(no_color=False, configs={}) is False +def test_should_do_markup_prefers_NO_COLOR_to_PY_COLORS(): + flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return( + 'True' + ) + flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return( + 'SomeValue' + ) + + assert module.should_do_markup(no_color=False, configs={}) is False + def test_multi_stream_handler_logs_to_handler_for_log_level(): error_handler = flexmock()