Переглянути джерело

update logger unit tests

  * update color config structure
  * add check for color: True in config
  * ensure interactive_console is called wherever it should
Theo Brigitte 10 місяців тому
батько
коміт
4c4fd92013
1 змінених файлів з 19 додано та 14 видалено
  1. 19 14
      tests/unit/test_logger.py

+ 19 - 14
tests/unit/test_logger.py

@@ -45,23 +45,27 @@ def test_interactive_console_true_when_isatty_and_TERM_is_not_dumb(capsys):
 
 
 def test_should_do_markup_respects_no_color_value():
+    flexmock(module).should_receive('interactive_console').never()
     assert module.should_do_markup(no_color=True, configs={}) is False
 
 
 def test_should_do_markup_respects_config_value():
-    assert (
-        module.should_do_markup(no_color=False, configs={'foo.yaml': {'output': {'color': False}}})
-        is False
-    )
+    flexmock(module).should_receive('interactive_console').never()
+    assert module.should_do_markup(no_color=False, configs={'foo.yaml': {'color': False}}) is False
+
+    flexmock(module).should_receive('interactive_console').and_return(True).once()
+    assert module.should_do_markup(no_color=False, configs={'foo.yaml': {'color': True}}) is True
 
 
 def test_should_do_markup_prefers_any_false_config_value():
+    flexmock(module).should_receive('interactive_console').never()
+
     assert (
         module.should_do_markup(
             no_color=False,
             configs={
-                'foo.yaml': {'output': {'color': True}},
-                'bar.yaml': {'output': {'color': False}},
+                'foo.yaml': {'color': True},
+                'bar.yaml': {'color': False},
             },
         )
         is False
@@ -80,25 +84,23 @@ def test_should_do_markup_respects_PY_COLORS_environment_variable():
 
 
 def test_should_do_markup_prefers_no_color_value_to_config_value():
-    assert (
-        module.should_do_markup(no_color=True, configs={'foo.yaml': {'output': {'color': True}}})
-        is False
-    )
+    flexmock(module).should_receive('interactive_console').never()
+
+    assert module.should_do_markup(no_color=True, configs={'foo.yaml': {'color': True}}) is False
 
 
 def test_should_do_markup_prefers_config_value_to_environment_variables():
     flexmock(module.os.environ).should_receive('get').and_return('True')
     flexmock(module).should_receive('to_bool').and_return(True)
+    flexmock(module).should_receive('interactive_console').never()
 
-    assert (
-        module.should_do_markup(no_color=False, configs={'foo.yaml': {'output': {'color': False}}})
-        is False
-    )
+    assert module.should_do_markup(no_color=False, configs={'foo.yaml': {'color': False}}) is False
 
 
 def test_should_do_markup_prefers_no_color_value_to_environment_variables():
     flexmock(module.os.environ).should_receive('get').and_return('True')
     flexmock(module).should_receive('to_bool').and_return(True)
+    flexmock(module).should_receive('interactive_console').never()
 
     assert module.should_do_markup(no_color=True, configs={}) is False
 
@@ -124,6 +126,7 @@ def test_should_do_markup_prefers_PY_COLORS_to_interactive_console_value():
 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('interactive_console').never()
 
     assert module.should_do_markup(no_color=False, configs={}) is False
 
@@ -131,6 +134,7 @@ def test_should_do_markup_prefers_NO_COLOR_to_interactive_console_value():
 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('interactive_console').never()
 
     assert module.should_do_markup(no_color=False, configs={}) is False
 
@@ -150,6 +154,7 @@ def test_should_do_markup_prefers_NO_COLOR_to_PY_COLORS():
     flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return(
         'SomeValue'
     )
+    flexmock(module).should_receive('interactive_console').never()
 
     assert module.should_do_markup(no_color=False, configs={}) is False