Skip to content

Commit 9fa2038

Browse files
committed
Fix running tests on Windows
1 parent 4a88906 commit 9fa2038

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

cli_ui/tests/test_cli_ui.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import io
33
import operator
4+
import os
45
import re
56
from typing import Iterator
67
from unittest import mock
@@ -47,12 +48,19 @@ def dumb_tty() -> DumbTTY:
4748

4849
@pytest.fixture
4950
def toggle_timestamp() -> Iterator[None]:
50-
cli_ui.CONFIG["timestamp"] = True
51+
cli_ui.setup(timestamp=True)
5152
yield
52-
cli_ui.CONFIG["timestamp"] = False
53+
cli_ui.setup(timestamp=False)
5354

5455

55-
def test_info_stdout_is_a_tty(smart_tty: io.StringIO) -> None:
56+
@pytest.fixture
57+
def always_color() -> Iterator[None]:
58+
cli_ui.setup(color="always")
59+
yield
60+
cli_ui.setup(color="auto")
61+
62+
63+
def test_info_with_colors(always_color: None, smart_tty: io.StringIO) -> None:
5664
# fmt: off
5765
cli_ui.info(
5866
cli_ui.red, "this is red", cli_ui.reset,
@@ -67,7 +75,7 @@ def test_info_stdout_is_a_tty(smart_tty: io.StringIO) -> None:
6775
assert actual == expected
6876

6977

70-
def test_update_title(smart_tty: SmartTTY) -> None:
78+
def test_update_title(always_color: None, smart_tty: SmartTTY) -> None:
7179
# fmt: off
7280
cli_ui.info(
7381
"Something", cli_ui.bold, "bold",
@@ -83,7 +91,7 @@ def test_update_title(smart_tty: SmartTTY) -> None:
8391
assert actual == expected
8492

8593

86-
def test_info_stdout_is_not_a_tty(dumb_tty: DumbTTY) -> None:
94+
def test_info_stdout_no_colors(dumb_tty: DumbTTY) -> None:
8795
# fmt: off
8896
cli_ui.info(
8997
cli_ui.red, "this is red", cli_ui.reset,
@@ -96,12 +104,18 @@ def test_info_stdout_is_not_a_tty(dumb_tty: DumbTTY) -> None:
96104
assert actual == expected
97105

98106

99-
def test_info_characters(smart_tty: SmartTTY) -> None:
107+
def test_info_characters(always_color: None, smart_tty: SmartTTY) -> None:
100108
cli_ui.info(
101109
"Doing stuff", cli_ui.ellipsis, "sucess", cli_ui.check, fileobj=smart_tty
102110
)
103111
actual = smart_tty.getvalue()
104-
expected = f"Doing stuff {RESET_ALL}{RESET_ALL}{RESET_ALL}sucess {RESET_ALL}{GREEN}{RESET_ALL}\n{RESET_ALL}"
112+
if os.name == "nt":
113+
success = "ok"
114+
ellipsis = "..."
115+
else:
116+
success = "✓"
117+
ellipsis = "…"
118+
expected = f"Doing stuff {RESET_ALL}{RESET_ALL}{ellipsis} {RESET_ALL}sucess {RESET_ALL}{GREEN}{success} {RESET_ALL}\n{RESET_ALL}"
105119
assert actual == expected
106120

107121

@@ -150,7 +164,7 @@ def test_table_with_dict_no_color(dumb_tty: DumbTTY) -> None:
150164
assert actual == expected
151165

152166

153-
def test_table_with_dict_and_color(smart_tty: SmartTTY) -> None:
167+
def test_table_with_dict_and_color(always_color: None, smart_tty: SmartTTY) -> None:
154168
data = {
155169
(cli_ui.bold, "Name",): [(cli_ui.green, "Alice"), (cli_ui.green, "Bob")],
156170
(cli_ui.bold, "Age",): [(cli_ui.blue, 24), (cli_ui.blue, 9)],
@@ -168,7 +182,7 @@ def test_table_with_dict_and_color(smart_tty: SmartTTY) -> None:
168182
assert actual == expected
169183

170184

171-
def test_table_with_lists_with_color(smart_tty: SmartTTY) -> None:
185+
def test_table_with_lists_with_color(always_color: None, smart_tty: SmartTTY) -> None:
172186
headers = ["name", "score"]
173187
data = [
174188
[(cli_ui.bold, "John"), (cli_ui.green, 10)],

0 commit comments

Comments
 (0)