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
Use alternative to ANSI control sequences in Jupyter notebooks #195
Changes from all commits
1b54701
2fcbe16
4984981
8c0de49
159f883
dbeb3ce
4a6f58f
eecc16b
da7ea5c
ed6b176
c81d120
e49f335
b8cf13a
a6b00ee
36652a9
df9d668
04da024
639cadb
30a9e89
4055a59
70be673
a056f23
c821dbc
24014a4
c77f9c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,16 @@ def reversal(request): | |
return request.param | ||
|
||
|
||
@pytest.fixture(scope="session", params=[True, False], ids=["terminal", "jupyter"]) | ||
def isatty_fixture(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def isatty_true(monkeypatch): | ||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) | ||
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, this doesn't correctly patch However, this works fine for a bunch of tests not using |
||
|
||
|
||
def color_id_func(case): | ||
if isinstance(case, tuple): | ||
color, _ = case | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
Test Yaspin attributes magic hidden in __getattr__. | ||
""" | ||
|
||
import sys | ||
pavdmyt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import pytest | ||
|
||
from yaspin import yaspin | ||
|
@@ -19,12 +21,13 @@ def test_set_spinner_by_name(attr_name): | |
|
||
|
||
# Values for ``color`` argument | ||
def test_color(color_test_cases): | ||
def test_color(monkeypatch, color_test_cases): | ||
color, expected = color_test_cases | ||
# ``None`` and ``""`` are skipped | ||
if not color: | ||
pytest.skip("{0} - unsupported case".format(repr(color))) | ||
|
||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) | ||
Comment on lines
+24
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe there is an easier way to do this over and over? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to make this patch at the module level, like this:
From the docs: https://docs.pytest.org/en/6.2.x/monkeypatch.html#global-patch-example-preventing-requests-from-remote-operations |
||
sp = yaspin() | ||
|
||
if isinstance(expected, Exception): | ||
|
@@ -37,12 +40,13 @@ def test_color(color_test_cases): | |
|
||
|
||
# Values for ``on_color`` argument | ||
def test_on_color(on_color_test_cases): | ||
def test_on_color(monkeypatch, on_color_test_cases): | ||
on_color, expected = on_color_test_cases | ||
# ``None`` and ``""`` are skipped | ||
if not on_color: | ||
pytest.skip("{0} - unsupported case".format(repr(on_color))) | ||
|
||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) | ||
sp = yaspin() | ||
|
||
if isinstance(expected, Exception): | ||
|
@@ -60,7 +64,8 @@ def test_on_color(on_color_test_cases): | |
@pytest.mark.parametrize( | ||
"attr", sorted([k for k, v in COLOR_MAP.items() if v == "attrs"]) | ||
) | ||
def test_attrs(attr): | ||
def test_attrs(monkeypatch, attr): | ||
monkeypatch.setattr(sys.stdout, "isatty", lambda: True) | ||
sp = yaspin() | ||
getattr(sp, attr) | ||
assert sp.attrs == [attr] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W504 and W503 are contradictory