示例#1
0
 def test_patch_item(self):
     """Test :class:`humanfriendly.testing.PatchedItem`."""
     instance = dict(my_item=True)
     assert instance['my_item'] is True
     with PatchedItem(instance, 'my_item', False) as return_value:
         assert return_value is instance
         assert instance['my_item'] is False
     assert instance['my_item'] is True
示例#2
0
 def test_env_disable(self):
     """Make sure ANSI escape sequences can be disabled using ``$NO_COLOR``."""
     with PatchedItem(os.environ, 'NO_COLOR', 'I like monochrome'):
         with CaptureOutput() as capturer:
             subprocess.check_call([
                 sys.executable, "-c", ";".join([
                     "import coloredlogs, logging",
                     "coloredlogs.install()",
                     "logging.info('Hello world')",
                 ]),
             ])
             output = capturer.get_text()
             assert ANSI_CSI not in output
示例#3
0
 def test_clipboard_enabled(self):
     """Test the detection whether the clipboard should be used."""
     # Make sure the clipboard is enabled by default on macOS.
     if platform.system().lower() == 'darwin':
         assert is_clipboard_supported() is True
     else:
         # Make sure the clipboard is used when $DISPLAY is set.
         with PatchedItem(os.environ, 'DISPLAY', ':0'):
             assert is_clipboard_supported() is True
         # Make sure the clipboard is not used when $DISPLAY isn't set.
         environment = os.environ.copy()
         environment.pop('DISPLAY', None)
         with PatchedAttribute(os, 'environ', environment):
             assert is_clipboard_supported() is False
示例#4
0
 def test_directory_variable(self):
     """Test support for ``$PASSWORD_STORE_DIR``."""
     with TemporaryDirectory() as directory:
         with PatchedItem(os.environ, DIRECTORY_VARIABLE, directory):
             program = PasswordStore()
             assert program.directory == directory
示例#5
0
 def test_disable_colored_cron_mailer(self):
     """Test that automatic ANSI to HTML conversion when running under ``cron`` can be disabled."""
     with PatchedItem(os.environ, 'CONTENT_TYPE', 'text/plain'):
         with ColoredCronMailer() as mailer:
             assert not mailer.is_enabled
示例#6
0
 def test_system_logging_override(self):
     """Make sure the :class:`coloredlogs.syslog.is_syslog_supported` respects the override."""
     with PatchedItem(os.environ, 'COLOREDLOGS_SYSLOG', 'true'):
         assert is_syslog_supported() is True
     with PatchedItem(os.environ, 'COLOREDLOGS_SYSLOG', 'false'):
         assert is_syslog_supported() is False