From 5973d5e70eb26b3129a7b56ed4f07bdb75a6bffa Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 18 Aug 2018 19:38:38 +0200 Subject: [PATCH] console: indent log messages correctly --- asv/console.py | 9 ++++++--- test/test_console.py | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/asv/console.py b/asv/console.py index b573bd03f..a7a6dacb4 100644 --- a/asv/console.py +++ b/asv/console.py @@ -274,9 +274,13 @@ def _stream_formatter(self, record): else: rest = parts[1] + indent = self._indent + 1 + if self._total: - color_print('[{0:6.02f}%] '.format( - (float(self._count) / self._total) * 100.0), end='') + progress_msg = '[{0:6.02f}%] '.format( + (float(self._count) / self._total) * 100.0) + color_print(progress_msg, end='') + indent += len(progress_msg) color_print('ยท' * self._indent, end='') color_print(' ', end='') @@ -299,7 +303,6 @@ def _stream_formatter(self, record): else: color = 'red' - indent = self._indent + 11 spaces = ' ' * indent color_print(first_line, color, end='') if rest is not None: diff --git a/test/test_console.py b/test/test_console.py index a0e141f34..282a38952 100644 --- a/test/test_console.py +++ b/test/test_console.py @@ -11,7 +11,7 @@ import locale import itertools -from asv.console import _write_with_fallback, color_print +from asv.console import _write_with_fallback, color_print, log def test_write_with_fallback(tmpdir, capfd): @@ -110,3 +110,19 @@ def test_color_print_nofail(capfd): assert 'indeed' in out assert 'really' in out assert 'not really' in out + + +def test_log_indent(capsys): + log.set_nitems(0) + log.info("First\nSecond") + + out, err = capsys.readouterr() + lines = out.lstrip().splitlines() + assert lines[0].index('First') == lines[1].index('Second') + + log.set_nitems(1) + log.info("First\nSecond") + + out, err = capsys.readouterr() + lines = out.lstrip().splitlines() + assert lines[0].index('First') == lines[1].index('Second')