From 833e4b14336894dea8c07e4a8727d6a3202220ca Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 19 Aug 2021 22:04:43 -0400 Subject: [PATCH] Add ASCII messages for OK/FAIL/SKIP lines Fixes #1421. --- CONTRIBUTORS | 1 + docs/changelog/1421.bugfix.rst | 1 + src/tox/util/spinner.py | 9 ++++++--- tests/unit/util/test_spinner.py | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/1421.bugfix.rst diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 14d9bbadf..d91bef347 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -20,6 +20,7 @@ Bastien Vallet Benoit Pierre Bernat Gabor Brett Langdon +Brett Smith Bruno Oliveira Carl Meyer Charles Brunet diff --git a/docs/changelog/1421.bugfix.rst b/docs/changelog/1421.bugfix.rst new file mode 100644 index 000000000..8e0a5ff54 --- /dev/null +++ b/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` diff --git a/src/tox/util/spinner.py b/src/tox/util/spinner.py index ef8fe6814..ee2258958 100644 --- a/src/tox/util/spinner.py +++ b/src/tox/util/spinner.py @@ -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 @@ -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] diff --git a/tests/unit/util/test_spinner.py b/tests/unit/util/test_spinner.py index 7c64ac453..2511d5848 100644 --- a/tests/unit/util/test_spinner.py +++ b/tests/unit/util/test_spinner.py @@ -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", [