From 620f9e64d648d2cc57969aa015d81dc6e50353d0 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 13 May 2019 20:49:20 -0700 Subject: [PATCH] A few more tests for new colored logging. --- borgmatic/logger.py | 4 ++-- tests/unit/test_logger.py | 46 +++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/borgmatic/logger.py b/borgmatic/logger.py index a6e0a70b..5df5a78c 100644 --- a/borgmatic/logger.py +++ b/borgmatic/logger.py @@ -21,11 +21,11 @@ def to_bool(arg): return False -def should_do_markup(no_colour): +def should_do_markup(no_color): ''' Determine if we should enable colorama marking up. ''' - if no_colour: + if no_color: 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 60633d9f..136c568b 100644 --- a/tests/unit/test_logger.py +++ b/tests/unit/test_logger.py @@ -1,17 +1,49 @@ import pytest +from flexmock import flexmock -from borgmatic.logger import to_bool +from borgmatic import logger as module @pytest.mark.parametrize('bool_val', (True, 'yes', 'on', '1', 'true', 'True', 1)) -def test_logger_to_bool_is_true(bool_val): - assert to_bool(bool_val) +def test_to_bool_parses_true_values(bool_val): + assert module.to_bool(bool_val) @pytest.mark.parametrize('bool_val', (False, 'no', 'off', '0', 'false', 'False', 0)) -def test_logger_to_bool_is_false(bool_val): - assert not to_bool(bool_val) +def test_to_bool_parses_false_values(bool_val): + assert not module.to_bool(bool_val) -def test_logger_to_bool_returns_none(): - assert to_bool(None) is None +def test_to_bool_passes_none_through(): + assert module.to_bool(None) is None + + +def test_should_do_markup_respects_no_color_value(): + assert module.should_do_markup(no_color=True) is False + + +def test_should_do_markup_respects_PY_COLORS_environment_variable(): + flexmock(module.os.environ).should_receive('get').and_return('True') + flexmock(module).should_receive('to_bool').and_return(True) + + assert module.should_do_markup(no_color=False) is True + + +def test_should_do_markup_prefers_no_color_value_to_PY_COLORS(): + flexmock(module.os.environ).should_receive('get').and_return('True') + flexmock(module).should_receive('to_bool').and_return(True) + + assert module.should_do_markup(no_color=True) is False + + +def test_should_do_markup_respects_stdout_tty_value(): + flexmock(module.os.environ).should_receive('get').and_return(None) + + assert module.should_do_markup(no_color=False) is False + + +def test_should_do_markup_prefers_PY_COLORS_to_stdout_tty_value(): + flexmock(module.os.environ).should_receive('get').and_return('True') + flexmock(module).should_receive('to_bool').and_return(True) + + assert module.should_do_markup(no_color=False) is True