From bce06d6f43bf404e6ef729fe6820ce48f8dc77b9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 2 Jul 2016 13:51:10 +0200 Subject: [PATCH 1/4] quteproc: mark expected errors as such Fixes #1611 This marks errors that are expected by a test with an "(Expected)" marker and white color (instead of red). The formatting of the log messages has been deferred to _render_log, since the .expected attribute is not correctly set right after we read the message. --- tests/end2end/fixtures/quteprocess.py | 23 +++++++++----- tests/end2end/fixtures/test_quteprocess.py | 36 ++++++++++++++++++---- tests/end2end/fixtures/testprocess.py | 1 + 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index c894acdc3..05d9865af 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -92,9 +92,10 @@ class LogLine(testprocess.Line): self.message = msg_match.group('message') self.expected = is_ignored_qt_message(self.message) + self.use_color = False def __str__(self): - return self.formatted_str(colorized=False) + return self.formatted_str(colorized=self.use_color) def formatted_str(self, colorized=True): """Return a formatted colorized line. @@ -113,7 +114,18 @@ class LogLine(testprocess.Line): r.module = self.module r.funcName = self.function - formatter = log.ColoredFormatter(log.EXTENDED_FMT, log.DATEFMT, '{', + format_str = log.EXTENDED_FMT + # Mark expected errors with (Expected) so it's less confusing for tests + # which expect errors but fail due to other errors. + if self.expected and self.loglevel >= log.LOG_LEVELS['ERROR']: + new_color = '{' + log.LOG_COLORS['DEBUG'] + '}' + format_str = format_str.replace('{log_color}', new_color) + format_str = re.sub(r'{levelname:(\d*)}', + # Leave away the padding because (Expected) is + # longer anyway. + r'{levelname} (Expected)', format_str) + + formatter = log.ColoredFormatter(format_str, log.DATEFMT, '{', use_colors=colorized) result = formatter.format(r) # Manually append the stringified traceback if one is present @@ -186,11 +198,8 @@ class QuteProc(testprocess.Process): else: raise - if self._config.getoption('--color') != 'no': - line_to_log = log_line.formatted_str() - else: - line_to_log = log_line.formatted_str(colorized=False) - self._log(line_to_log) + log_line.use_color = self._config.getoption('--color') != 'no' + self._log(log_line) start_okay_message_load = ( "load status for threshold and From e2b521a408d75c8419b707c3d59c6c9f1ef2afcb Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 2 Jul 2016 16:51:58 +0200 Subject: [PATCH 2/4] fix lint --- tests/end2end/fixtures/test_quteprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/end2end/fixtures/test_quteprocess.py b/tests/end2end/fixtures/test_quteprocess.py index dc3515e91..5de7ae5f4 100644 --- a/tests/end2end/fixtures/test_quteprocess.py +++ b/tests/end2end/fixtures/test_quteprocess.py @@ -221,8 +221,8 @@ def test_log_line_parse(data, attrs): {'created': 0, 'levelname': 'ERROR', 'name': 'foo', 'module': 'bar', 'funcName': 'qux', 'lineno': 10, 'levelno': 40, 'message': 'quux'}, True, True, - '\033[32m{timestamp}\033[0m \033[37mERROR (Expected)\033[0m \033[36mfoo' - ' bar:qux:10\033[0m \033[37mquux\033[0m', + '\033[32m{timestamp}\033[0m \033[37mERROR (Expected)\033[0m ' + '\033[36mfoo bar:qux:10\033[0m \033[37mquux\033[0m', ), ], ids=['normal', 'traceback', 'colored', 'expected error', 'expected other', 'expected error colorized']) From 4863df5ac8810f9ab2c96191237b0e5414b97251 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 2 Jul 2016 17:19:19 +0200 Subject: [PATCH 3/4] quteprocess: also mark expected WARNINGs --- tests/end2end/fixtures/quteprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 05d9865af..0b0deeb83 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -117,7 +117,7 @@ class LogLine(testprocess.Line): format_str = log.EXTENDED_FMT # Mark expected errors with (Expected) so it's less confusing for tests # which expect errors but fail due to other errors. - if self.expected and self.loglevel >= log.LOG_LEVELS['ERROR']: + if self.expected and self.loglevel > logging.INFO: new_color = '{' + log.LOG_COLORS['DEBUG'] + '}' format_str = format_str.replace('{log_color}', new_color) format_str = re.sub(r'{levelname:(\d*)}', From ee9d3b6a49ede450b8a6d7fc54c10739c64cc599 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 2 Jul 2016 17:22:40 +0200 Subject: [PATCH 4/4] quteprocess: replace Expected with expected --- tests/end2end/fixtures/quteprocess.py | 6 +++--- tests/end2end/fixtures/test_quteprocess.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 0b0deeb83..2058d585e 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -115,15 +115,15 @@ class LogLine(testprocess.Line): r.funcName = self.function format_str = log.EXTENDED_FMT - # Mark expected errors with (Expected) so it's less confusing for tests + # Mark expected errors with (expected) so it's less confusing for tests # which expect errors but fail due to other errors. if self.expected and self.loglevel > logging.INFO: new_color = '{' + log.LOG_COLORS['DEBUG'] + '}' format_str = format_str.replace('{log_color}', new_color) format_str = re.sub(r'{levelname:(\d*)}', - # Leave away the padding because (Expected) is + # Leave away the padding because (expected) is # longer anyway. - r'{levelname} (Expected)', format_str) + r'{levelname} (expected)', format_str) formatter = log.ColoredFormatter(format_str, log.DATEFMT, '{', use_colors=colorized) diff --git a/tests/end2end/fixtures/test_quteprocess.py b/tests/end2end/fixtures/test_quteprocess.py index 5de7ae5f4..4c9f74f63 100644 --- a/tests/end2end/fixtures/test_quteprocess.py +++ b/tests/end2end/fixtures/test_quteprocess.py @@ -207,7 +207,7 @@ def test_log_line_parse(data, attrs): {'created': 0, 'levelname': 'ERROR', 'name': 'foo', 'module': 'bar', 'funcName': 'qux', 'lineno': 10, 'levelno': 40, 'message': 'quux'}, False, True, - '{timestamp} ERROR (Expected) foo bar:qux:10 quux', + '{timestamp} ERROR (expected) foo bar:qux:10 quux', ), # Expected other message (i.e. should make no difference) ( @@ -221,7 +221,7 @@ def test_log_line_parse(data, attrs): {'created': 0, 'levelname': 'ERROR', 'name': 'foo', 'module': 'bar', 'funcName': 'qux', 'lineno': 10, 'levelno': 40, 'message': 'quux'}, True, True, - '\033[32m{timestamp}\033[0m \033[37mERROR (Expected)\033[0m ' + '\033[32m{timestamp}\033[0m \033[37mERROR (expected)\033[0m ' '\033[36mfoo bar:qux:10\033[0m \033[37mquux\033[0m', ), ], ids=['normal', 'traceback', 'colored', 'expected error', 'expected other',