Explorar o código

Fix handling of the NO_COLOR environment variable to ignore an empty value (#835).

Dan Helfman hai 1 ano
pai
achega
f8f6560502
Modificáronse 4 ficheiros con 14 adicións e 5 borrados
  1. 3 0
      NEWS
  2. 1 2
      borgmatic/logger.py
  3. 1 1
      setup.py
  4. 9 2
      tests/unit/test_logger.py

+ 3 - 0
NEWS

@@ -1,3 +1,6 @@
+1.8.10.dev0
+ * Fix handling of the NO_COLOR environment variable to ignore an empty value.
+
 1.8.9
 1.8.9
  * #311: Add custom dump/restore command options for MySQL and MariaDB.
  * #311: Add custom dump/restore command options for MySQL and MariaDB.
  * #811: Add an "access_token" option to the ntfy monitoring hook for authenticating
  * #811: Add an "access_token" option to the ntfy monitoring hook for authenticating

+ 1 - 2
borgmatic/logger.py

@@ -41,8 +41,7 @@ def should_do_markup(no_color, configs):
     if any(config.get('output', {}).get('color') is False for config in configs.values()):
     if any(config.get('output', {}).get('color') is False for config in configs.values()):
         return False
         return False
 
 
-    no_color_env = os.environ.get('NO_COLOR', None)
-    if no_color_env is not None:
+    if os.environ.get('NO_COLOR', None):
         return False
         return False
 
 
     py_colors = os.environ.get('PY_COLORS', None)
     py_colors = os.environ.get('PY_COLORS', None)

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 from setuptools import find_packages, setup
 
 
-VERSION = '1.8.9'
+VERSION = '1.8.10.dev0'
 
 
 
 
 setup(
 setup(

+ 9 - 2
tests/unit/test_logger.py

@@ -116,7 +116,7 @@ def test_should_do_markup_prefers_PY_COLORS_to_interactive_console_value():
     )
     )
     flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return(None)
     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('to_bool').and_return(True)
-    flexmock(module).should_receive('interactive_console').and_return(False)
+    flexmock(module).should_receive('interactive_console').never()
 
 
     assert module.should_do_markup(no_color=False, configs={}) is True
     assert module.should_do_markup(no_color=False, configs={}) is True
 
 
@@ -124,7 +124,6 @@ def test_should_do_markup_prefers_PY_COLORS_to_interactive_console_value():
 def test_should_do_markup_prefers_NO_COLOR_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('PY_COLORS', None).and_return(None)
     flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('True')
     flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('True')
-    flexmock(module).should_receive('interactive_console').and_return(False)
 
 
     assert module.should_do_markup(no_color=False, configs={}) is False
     assert module.should_do_markup(no_color=False, configs={}) is False
 
 
@@ -136,6 +135,14 @@ def test_should_do_markup_respects_NO_COLOR_environment_variable():
     assert module.should_do_markup(no_color=False, configs={}) is False
     assert module.should_do_markup(no_color=False, configs={}) is False
 
 
 
 
+def test_should_do_markup_ignores_empty_NO_COLOR_environment_variable():
+    flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('')
+    flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return(None)
+    flexmock(module).should_receive('interactive_console').and_return(True)
+
+    assert module.should_do_markup(no_color=False, configs={}) is True
+
+
 def test_should_do_markup_prefers_NO_COLOR_to_PY_COLORS():
 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(
     flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return(
         'True'
         'True'