You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
5.2 KiB
102 lines
5.2 KiB
diff --git a/coloredlogs/tests.py b/coloredlogs/tests.py
|
|
index 38f2d97..c4353f1 100644
|
|
--- a/coloredlogs/tests.py
|
|
+++ b/coloredlogs/tests.py
|
|
@@ -184,48 +184,6 @@ class ColoredLogsTestCase(TestCase):
|
|
# Make sure colored logging is disabled.
|
|
assert not isinstance(handler.formatter, ColoredFormatter)
|
|
|
|
- def test_system_logging(self):
|
|
- """Make sure the :class:`coloredlogs.syslog.SystemLogging` context manager works."""
|
|
- system_log_file = self.find_system_log()
|
|
- expected_message = random_string(50)
|
|
- with SystemLogging(programname='coloredlogs-test-suite') as syslog:
|
|
- if not syslog:
|
|
- return self.skipTest("couldn't connect to syslog daemon")
|
|
- # When I tried out the system logging support on macOS 10.13.1 on
|
|
- # 2018-01-05 I found that while WARNING and ERROR messages show up
|
|
- # in the system log DEBUG and INFO messages don't. This explains
|
|
- # the importance of the level of the log message below.
|
|
- logging.error("%s", expected_message)
|
|
- # Retry the following assertion (for up to 60 seconds) to give the
|
|
- # logging daemon time to write our log message to disk. This
|
|
- # appears to be needed on MacOS workers on Travis CI, see:
|
|
- # https://travis-ci.org/xolox/python-coloredlogs/jobs/325245853
|
|
- retry(lambda: check_contents(system_log_file, expected_message, True))
|
|
-
|
|
- def test_syslog_shortcut_simple(self):
|
|
- """Make sure that ``coloredlogs.install(syslog=True)`` works."""
|
|
- system_log_file = self.find_system_log()
|
|
- expected_message = random_string(50)
|
|
- with cleanup_handlers():
|
|
- # See test_system_logging() for the importance of this log level.
|
|
- coloredlogs.install(syslog=True)
|
|
- logging.error("%s", expected_message)
|
|
- # See the comments in test_system_logging() on why this is retried.
|
|
- retry(lambda: check_contents(system_log_file, expected_message, True))
|
|
-
|
|
- def test_syslog_shortcut_enhanced(self):
|
|
- """Make sure that ``coloredlogs.install(syslog='warning')`` works."""
|
|
- system_log_file = self.find_system_log()
|
|
- the_expected_message = random_string(50)
|
|
- not_an_expected_message = random_string(50)
|
|
- with cleanup_handlers():
|
|
- # See test_system_logging() for the importance of these log levels.
|
|
- coloredlogs.install(syslog='error')
|
|
- logging.warning("%s", not_an_expected_message)
|
|
- logging.error("%s", the_expected_message)
|
|
- # See the comments in test_system_logging() on why this is retried.
|
|
- retry(lambda: check_contents(system_log_file, the_expected_message, True))
|
|
- retry(lambda: check_contents(system_log_file, not_an_expected_message, False))
|
|
|
|
def test_name_normalization(self):
|
|
"""Make sure :class:`~coloredlogs.NameNormalizer` works as intended."""
|
|
@@ -369,34 +327,6 @@ class ColoredLogsTestCase(TestCase):
|
|
logging.info("This should be timestamped according to #45.")
|
|
assert re.match(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{4}\s', stream.getvalue())
|
|
|
|
- def test_plain_text_output_format(self):
|
|
- """Inspect the plain text output of coloredlogs."""
|
|
- logger = VerboseLogger(random_string(25))
|
|
- stream = StringIO()
|
|
- install(level=logging.NOTSET, logger=logger, stream=stream)
|
|
- # Test that filtering on severity works.
|
|
- logger.setLevel(logging.INFO)
|
|
- logger.debug("No one should see this message.")
|
|
- assert len(stream.getvalue().strip()) == 0
|
|
- # Test that the default output format looks okay in plain text.
|
|
- logger.setLevel(logging.NOTSET)
|
|
- for method, severity in ((logger.debug, 'DEBUG'),
|
|
- (logger.info, 'INFO'),
|
|
- (logger.verbose, 'VERBOSE'),
|
|
- (logger.warning, 'WARNING'),
|
|
- (logger.error, 'ERROR'),
|
|
- (logger.critical, 'CRITICAL')):
|
|
- # Prepare the text.
|
|
- text = "This is a message with severity %r." % severity.lower()
|
|
- # Log the message with the given severity.
|
|
- method(text)
|
|
- # Get the line of output generated by the handler.
|
|
- output = stream.getvalue()
|
|
- lines = output.splitlines()
|
|
- last_line = lines[-1]
|
|
- assert text in last_line
|
|
- assert severity in last_line
|
|
- assert PLAIN_TEXT_PATTERN.match(last_line)
|
|
|
|
def test_html_conversion(self):
|
|
"""Check the conversion from ANSI escape sequences to HTML."""
|
|
@@ -503,12 +433,6 @@ class ColoredLogsTestCase(TestCase):
|
|
for name in 'debug', 'info', 'warning', 'error', 'critical':
|
|
assert name.upper() in output
|
|
|
|
- def test_cli_conversion(self):
|
|
- """Test the command line HTML conversion."""
|
|
- output = main('coloredlogs', '--convert', 'coloredlogs', '--demo', capture=True)
|
|
- # Make sure the output is encoded as HTML.
|
|
- assert '<span' in output
|
|
-
|
|
def test_empty_conversion(self):
|
|
"""
|
|
Test that conversion of empty output produces no HTML.
|