Skip to content

Commit

Permalink
Add ASCII messages for OK/FAIL/SKIP lines
Browse files Browse the repository at this point in the history
Fixes #1421.
  • Loading branch information
brettcs committed Aug 21, 2021
1 parent db680f8 commit 833e4b1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -20,6 +20,7 @@ Bastien Vallet
Benoit Pierre
Bernat Gabor
Brett Langdon
Brett Smith
Bruno Oliveira
Carl Meyer
Charles Brunet
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1421.bugfix.rst
@@ -0,0 +1 @@
``--parallel`` reports now show ASCII OK/FAIL/SKIP lines when full Unicode output is not available - by :user:`brettcs`
9 changes: 6 additions & 3 deletions src/tox/util/spinner.py
Expand Up @@ -36,6 +36,9 @@ class Spinner(object):
CLEAR_LINE = "\033[K"
max_width = 120
FRAMES = SpinnerMessage("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏", "|-+x*")
OK_FLAG = SpinnerMessage("✔ OK", "[ OK ]")
FAIL_FLAG = SpinnerMessage("✖ FAIL", "[FAIL]")
SKIP_FLAG = SpinnerMessage("⚠ SKIP", "[SKIP]")

def __init__(self, enabled=True, refresh_rate=0.1):
self.refresh_rate = refresh_rate
Expand Down Expand Up @@ -100,13 +103,13 @@ def add(self, name):
self._envs[name] = datetime.now()

def succeed(self, key):
self.finalize(key, "✔ OK", green=True)
self.finalize(key, self.OK_FLAG.for_file(self._file), green=True)

def fail(self, key):
self.finalize(key, "✖ FAIL", red=True)
self.finalize(key, self.FAIL_FLAG.for_file(self._file), red=True)

def skip(self, key):
self.finalize(key, "⚠ SKIP", white=True)
self.finalize(key, self.SKIP_FLAG.for_file(self._file), white=True)

def finalize(self, key, status, **kwargs):
start_at = self._envs[key]
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/util/test_spinner.py
Expand Up @@ -113,6 +113,31 @@ def test_spinner_stdout_not_unicode(mocker, capfd):
assert all(f in written for f in spin.frames)


@freeze_time("2012-01-14")
def test_spinner_report_not_unicode(mocker, capfd):
stdout = mocker.patch("tox.util.spinner.sys.stdout")
stdout.encoding = "ascii"
# Disable color to simplify parsing output strings
stdout.isatty = lambda: False
with spinner.Spinner(refresh_rate=100) as spin:
spin.stream.write(os.linesep)
spin.add("ok!")
spin.add("fail!")
spin.add("skip!")
spin.succeed("ok!")
spin.fail("fail!")
spin.skip("skip!")
lines = "".join(args[0] for args, _ in stdout.write.call_args_list).split(os.linesep)
del lines[0]
expected = [
"\r{}[ OK ] ok! in 0.0 seconds".format(spin.CLEAR_LINE),
"\r{}[FAIL] fail! in 0.0 seconds".format(spin.CLEAR_LINE),
"\r{}[SKIP] skip! in 0.0 seconds".format(spin.CLEAR_LINE),
"\r{}".format(spin.CLEAR_LINE),
]
assert lines == expected


@pytest.mark.parametrize(
"seconds, expected",
[
Expand Down

0 comments on commit 833e4b1

Please sign in to comment.