Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: indent log messages correctly #701

Merged
merged 1 commit into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions asv/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='')
Expand All @@ -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:
Expand Down
18 changes: 17 additions & 1 deletion test/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')