1
1
import datetime
2
2
import io
3
3
import operator
4
+ import os
4
5
import re
5
6
from typing import Iterator
6
7
from unittest import mock
@@ -47,12 +48,19 @@ def dumb_tty() -> DumbTTY:
47
48
48
49
@pytest .fixture
49
50
def toggle_timestamp () -> Iterator [None ]:
50
- cli_ui .CONFIG [ " timestamp" ] = True
51
+ cli_ui .setup ( timestamp = True )
51
52
yield
52
- cli_ui .CONFIG [ " timestamp" ] = False
53
+ cli_ui .setup ( timestamp = False )
53
54
54
55
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 :
56
64
# fmt: off
57
65
cli_ui .info (
58
66
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:
67
75
assert actual == expected
68
76
69
77
70
- def test_update_title (smart_tty : SmartTTY ) -> None :
78
+ def test_update_title (always_color : None , smart_tty : SmartTTY ) -> None :
71
79
# fmt: off
72
80
cli_ui .info (
73
81
"Something" , cli_ui .bold , "bold" ,
@@ -83,7 +91,7 @@ def test_update_title(smart_tty: SmartTTY) -> None:
83
91
assert actual == expected
84
92
85
93
86
- def test_info_stdout_is_not_a_tty (dumb_tty : DumbTTY ) -> None :
94
+ def test_info_stdout_no_colors (dumb_tty : DumbTTY ) -> None :
87
95
# fmt: off
88
96
cli_ui .info (
89
97
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:
96
104
assert actual == expected
97
105
98
106
99
- def test_info_characters (smart_tty : SmartTTY ) -> None :
107
+ def test_info_characters (always_color : None , smart_tty : SmartTTY ) -> None :
100
108
cli_ui .info (
101
109
"Doing stuff" , cli_ui .ellipsis , "sucess" , cli_ui .check , fileobj = smart_tty
102
110
)
103
111
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 } "
105
119
assert actual == expected
106
120
107
121
@@ -150,7 +164,7 @@ def test_table_with_dict_no_color(dumb_tty: DumbTTY) -> None:
150
164
assert actual == expected
151
165
152
166
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 :
154
168
data = {
155
169
(cli_ui .bold , "Name" ,): [(cli_ui .green , "Alice" ), (cli_ui .green , "Bob" )],
156
170
(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:
168
182
assert actual == expected
169
183
170
184
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 :
172
186
headers = ["name" , "score" ]
173
187
data = [
174
188
[(cli_ui .bold , "John" ), (cli_ui .green , 10 )],
0 commit comments