Skip to content

Commit a947e62

Browse files
committed
update unit tests mock for new approach to TTY testing for ANSI color use
1 parent c011e58 commit a947e62

File tree

4 files changed

+31
-53
lines changed

4 files changed

+31
-53
lines changed

tests/test_contours.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
from fontTools.ttLib import TTFont
77
from pathins.contours import contours_run, number_of_contours
8+
import pathins.stringbuilder
89

910
TESTFONT_PATH_1 = os.path.join(
1011
"tests", "testfiles", "fonts", "NotoSans-Regular.subset1.ttf"
@@ -80,8 +81,7 @@ def test_contours_run_single_glyph_noncomposite_default(capsys, monkeypatch):
8081
def mock_isatty():
8182
return True
8283

83-
# apply the monkeypatch for sys.stdout.isatty()
84-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
84+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
8585

8686
args = parser.parse_args([TESTFONT_PATH_1, "A"])
8787
contours_run(args)
@@ -96,8 +96,7 @@ def test_contours_run_single_glyph_noncomposite_nocolor(capsys, monkeypatch):
9696
def mock_isatty():
9797
return True
9898

99-
# apply the monkeypatch for sys.stdout.isatty()
100-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
99+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
101100

102101
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "A"])
103102
contours_run(args)
@@ -112,8 +111,7 @@ def test_contours_run_single_glyph_composite_default(capsys, monkeypatch):
112111
def mock_isatty():
113112
return True
114113

115-
# apply the monkeypatch for sys.stdout.isatty()
116-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
114+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
117115

118116
args = parser.parse_args([TESTFONT_PATH_1, "uni2E2E"])
119117
contours_run(args)
@@ -128,8 +126,7 @@ def test_contours_run_single_glyph_composite_nocolor(capsys, monkeypatch):
128126
def mock_isatty():
129127
return True
130128

131-
# apply the monkeypatch for sys.stdout.isatty()
132-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
129+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
133130

134131
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "uni2E2E"])
135132
contours_run(args)
@@ -144,8 +141,7 @@ def test_contours_run_multi_glyph_composite_default(capsys, monkeypatch):
144141
def mock_isatty():
145142
return True
146143

147-
# apply the monkeypatch for sys.stdout.isatty()
148-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
144+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
149145

150146
args = parser.parse_args([TESTFONT_PATH_1])
151147
contours_run(args)
@@ -165,8 +161,7 @@ def test_contours_run_multi_glyph_composite_nocolor(capsys, monkeypatch):
165161
def mock_isatty():
166162
return True
167163

168-
# apply the monkeypatch for sys.stdout.isatty()
169-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
164+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
170165

171166
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1])
172167
contours_run(args)

tests/test_coordinates.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pathins.coordinates import coordinates_run
7+
import pathins.stringbuilder
78

89
TESTFONT_PATH_1 = os.path.join(
910
"tests", "testfiles", "fonts", "NotoSans-Regular.subset1.ttf"
@@ -65,8 +66,7 @@ def test_coordinates_run_single_glyph_noncomposite_default(capsys, monkeypatch):
6566
def mock_isatty():
6667
return True
6768

68-
# apply the monkeypatch for sys.stdout.isatty()
69-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
69+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
7070

7171
args = parser.parse_args([TESTFONT_PATH_1, "A"])
7272
coordinates_run(args)
@@ -93,8 +93,7 @@ def test_coordinates_run_single_glyph_noncomposite_nocolor(capsys, monkeypatch):
9393
def mock_isatty():
9494
return True
9595

96-
# apply the monkeypatch for sys.stdout.isatty()
97-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
96+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
9897

9998
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "A"])
10099
coordinates_run(args)
@@ -131,8 +130,7 @@ def test_coordinates_run_single_glyph_composite_default(capsys, monkeypatch):
131130
def mock_isatty():
132131
return True
133132

134-
# apply the monkeypatch for sys.stdout.isatty()
135-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
133+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
136134

137135
args = parser.parse_args([TESTFONT_PATH_1, "uni2E2E"])
138136
coordinates_run(args)
@@ -164,8 +162,7 @@ def test_coordinates_run_single_glyph_composite_nocolor(capsys, monkeypatch):
164162
def mock_isatty():
165163
return True
166164

167-
# apply the monkeypatch for sys.stdout.isatty()
168-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
165+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
169166

170167
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "uni2E2E"])
171168
coordinates_run(args)
@@ -198,8 +195,7 @@ def test_coordinates_run_multi_glyph_default(capsys, monkeypatch):
198195
def mock_isatty():
199196
return True
200197

201-
# apply the monkeypatch for sys.stdout.isatty()
202-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
198+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
203199

204200
args = parser.parse_args([TESTFONT_PATH_1])
205201
coordinates_run(args)
@@ -266,8 +262,7 @@ def test_coordinates_run_multi_glyph_nocolor(capsys, monkeypatch):
266262
def mock_isatty():
267263
return True
268264

269-
# apply the monkeypatch for sys.stdout.isatty()
270-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
265+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
271266

272267
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1])
273268
coordinates_run(args)

tests/test_direction.py

+9-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pathins.direction import direction_run
7+
import pathins.stringbuilder
78

89
TESTFONT_PATH_1 = os.path.join(
910
"tests", "testfiles", "fonts", "NotoSans-Regular.subset1.ttf"
@@ -61,8 +62,7 @@ def test_direction_run_single_glyph_non_composite_no_contours_default(
6162
def mock_isatty():
6263
return True
6364

64-
# apply the monkeypatch for sys.stdout.isatty()
65-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
65+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
6666

6767
args = parser.parse_args([TESTFONT_PATH_1, ".notdef"])
6868
direction_run(args)
@@ -79,8 +79,7 @@ def test_direction_run_single_glyph_non_composite_no_contours_nocolor(
7979
def mock_isatty():
8080
return True
8181

82-
# apply the monkeypatch for sys.stdout.isatty()
83-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
82+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
8483

8584
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, ".notdef"])
8685
direction_run(args)
@@ -95,8 +94,7 @@ def test_direction_run_single_glyph_non_composite_clockwise_default(capsys, monk
9594
def mock_isatty():
9695
return True
9796

98-
# apply the monkeypatch for sys.stdout.isatty()
99-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
97+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
10098

10199
args = parser.parse_args([TESTFONT_PATH_1, "A"])
102100
direction_run(args)
@@ -111,8 +109,7 @@ def test_dierection_run_single_glyph_non_composite_clockwise_nocolor(capsys, mon
111109
def mock_isatty():
112110
return True
113111

114-
# apply the monkeypatch for sys.stdout.isatty()
115-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
112+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
116113

117114
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "A"])
118115
direction_run(args)
@@ -129,8 +126,7 @@ def test_direction_run_single_glyph_composite_counter_clockwise_default(
129126
def mock_isatty():
130127
return True
131128

132-
# apply the monkeypatch for sys.stdout.isatty()
133-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
129+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
134130

135131
args = parser.parse_args([TESTFONT_PATH_1, "uni2E2E"])
136132
direction_run(args)
@@ -148,8 +144,7 @@ def test_direction_run_single_glyph_composite_counter_clockwise_nocolor(
148144
def mock_isatty():
149145
return True
150146

151-
# apply the monkeypatch for sys.stdout.isatty()
152-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
147+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
153148

154149
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "uni2E2E"])
155150
direction_run(args)
@@ -169,8 +164,7 @@ def test_direction_run_full_glyph_default(capsys, monkeypatch):
169164
def mock_isatty():
170165
return True
171166

172-
# apply the monkeypatch for sys.stdout.isatty()
173-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
167+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
174168

175169
args = parser.parse_args([TESTFONT_PATH_1])
176170
direction_run(args)
@@ -192,8 +186,7 @@ def test_direction_run_full_glyph_nocolor(capsys, monkeypatch):
192186
def mock_isatty():
193187
return True
194188

195-
# apply the monkeypatch for sys.stdout.isatty()
196-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
189+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
197190

198191
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1])
199192
direction_run(args)

tests/test_path.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pathins.path import path_run
7+
import pathins.stringbuilder
78

89
TESTFONT_PATH_1 = os.path.join("tests", "testfiles", "fonts", "RobotoMono-subset1.ttf")
910

@@ -58,7 +59,7 @@ def mock_isatty():
5859
return True
5960

6061
# apply the monkeypatch for sys.stdout.isatty()
61-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
62+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
6263

6364
args = parser.parse_args([TESTFONT_PATH_1, "A"])
6465
path_run(args)
@@ -74,8 +75,7 @@ def test_path_run_single_glyph_non_composite_nocolor_with_option(capsys, monkeyp
7475
def mock_isatty():
7576
return True
7677

77-
# apply the monkeypatch for sys.stdout.isatty()
78-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
78+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
7979

8080
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "A"])
8181
path_run(args)
@@ -106,8 +106,7 @@ def test_path_run_single_glyph_composite_default(capsys, monkeypatch):
106106
def mock_isatty():
107107
return True
108108

109-
# apply the monkeypatch for sys.stdout.isatty()
110-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
109+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
111110

112111
args = parser.parse_args([TESTFONT_PATH_1, "Scedilla"])
113112
path_run(args)
@@ -123,8 +122,7 @@ def test_path_run_single_glyph_composite_nocolor_with_option(capsys, monkeypatch
123122
def mock_isatty():
124123
return True
125124

126-
# apply the monkeypatch for sys.stdout.isatty()
127-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
125+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
128126

129127
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1, "Scedilla"])
130128
path_run(args)
@@ -153,8 +151,7 @@ def test_path_run_single_glyph_no_contours_default(capsys, monkeypatch):
153151
def mock_isatty():
154152
return True
155153

156-
# apply the monkeypatch for sys.stdout.isatty()
157-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
154+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
158155

159156
args = parser.parse_args([TESTFONT_PATH_1, ".notdef"])
160157
path_run(args)
@@ -190,8 +187,7 @@ def test_path_run_full_glyph_set_default(capsys, monkeypatch):
190187
def mock_isatty():
191188
return True
192189

193-
# apply the monkeypatch for sys.stdout.isatty()
194-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
190+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
195191

196192
args = parser.parse_args([TESTFONT_PATH_1])
197193
path_run(args)
@@ -229,8 +225,7 @@ def test_path_run_full_glyph_set_nocolor_flag(capsys, monkeypatch):
229225
def mock_isatty():
230226
return True
231227

232-
# apply the monkeypatch for sys.stdout.isatty()
233-
monkeypatch.setattr(sys.stdout, "isatty", mock_isatty)
228+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
234229

235230
args = parser.parse_args(["--nocolor", TESTFONT_PATH_1])
236231
path_run(args)

0 commit comments

Comments
 (0)