Skip to content

Commit bb413fb

Browse files
Trying to fix tests on windows (#93)
* .startswith('/') -> .is_absolute() * normalise_output function in tests * Remove xfails for windows * Fix test_os_environ for windows * Remove unused re import * Handle test_print_subprocess and test_odd_path in windows * normalise_output in test_colours * Relative imports of tests.utils Co-authored-by: Samuel Colvin <samcolvin@gmail.com> * defer pathlib import * set CI to work on windows * fix test_use_highlight_auto_win * fix test_use_highlight_auto_win, take 2 * xfail test_starred_kwargs on windows Co-authored-by: Samuel Colvin <samcolvin@gmail.com> Co-authored-by: Samuel Colvin <s@muelcolvin.com>
1 parent b30eead commit bb413fb

File tree

7 files changed

+76
-71
lines changed

7 files changed

+76
-71
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ jobs:
5858
- run: pip freeze
5959

6060
- name: test with extras
61-
run: |
62-
make test
63-
coverage xml
61+
run: make test
62+
63+
- run: coverage xml
6464

6565
- uses: codecov/codecov-action@v2.0.3
6666
with:
@@ -71,9 +71,9 @@ jobs:
7171
run: pip uninstall -y multidict numpy pydantic asyncpg sqlalchemy
7272

7373
- name: test without extras
74-
run: |
75-
make test
76-
coverage xml
74+
run: make test
75+
76+
- run: coverage xml
7777

7878
- uses: codecov/codecov-action@v2.0.3
7979
with:

devtools/debug.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,16 @@ def _process(self, args, kwargs) -> DebugOutput:
141141
warning=self._show_warnings and 'error parsing code, call stack too shallow',
142142
)
143143

144-
filename = call_frame.f_code.co_filename
145144
function = call_frame.f_code.co_name
146-
if filename.startswith('/'):
147-
# make the path relative
148-
from pathlib import Path
149145

146+
from pathlib import Path
147+
148+
path = Path(call_frame.f_code.co_filename)
149+
if path.is_absolute():
150+
# make the path relative
150151
cwd = Path('.').resolve()
151152
try:
152-
filename = str(Path(filename).relative_to(cwd))
153+
path = path.relative_to(cwd)
153154
except ValueError:
154155
# happens if filename path is not within CWD
155156
pass
@@ -173,7 +174,7 @@ def _process(self, args, kwargs) -> DebugOutput:
173174
arguments = list(self._process_args(ex, args, kwargs))
174175

175176
return self.output_class(
176-
filename=filename,
177+
filename=str(path),
177178
lineno=lineno,
178179
frame=function,
179180
arguments=arguments,

tests/test_expr_render.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
import asyncio
2-
import re
32
import sys
43

54
import pytest
65

76
from devtools import Debug, debug
87

8+
from .utils import normalise_output
9+
910

1011
def foobar(a, b, c):
1112
return a + b + c
1213

1314

14-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
1515
def test_simple():
1616
a = [1, 2, 3]
1717
v = debug.format(len(a))
18-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
18+
s = normalise_output(str(v))
1919
# print(s)
2020
assert (
2121
'tests/test_expr_render.py:<line no> test_simple\n'
2222
' len(a): 3 (int)'
2323
) == s
2424

2525

26-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
2726
def test_subscription():
2827
a = {1: 2}
2928
v = debug.format(a[1])
30-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
29+
s = normalise_output(str(v))
3130
assert (
3231
'tests/test_expr_render.py:<line no> test_subscription\n'
3332
' a[1]: 2 (int)'
3433
) == s
3534

3635

37-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
3836
def test_exotic_types():
3937
aa = [1, 2, 3]
4038
v = debug.format(
@@ -49,8 +47,7 @@ def test_exotic_types():
4947
{a: a + 1 for a in aa},
5048
(a for a in aa),
5149
)
52-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
53-
s = re.sub(r'(at 0x)\w+', r'\1<hash>', s)
50+
s = normalise_output(str(v))
5451
print('\n---\n{}\n---'.format(v))
5552

5653
# Generator expression source changed in 3.8 to include parentheses, see:
@@ -83,68 +80,63 @@ def test_exotic_types():
8380
) == s
8481

8582

86-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
8783
def test_newline():
8884
v = debug.format(
8985
foobar(1, 2, 3))
90-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
86+
s = normalise_output(str(v))
9187
# print(s)
9288
assert (
9389
'tests/test_expr_render.py:<line no> test_newline\n'
9490
' foobar(1, 2, 3): 6 (int)'
9591
) == s
9692

9793

98-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
9994
def test_trailing_bracket():
10095
v = debug.format(
10196
foobar(1, 2, 3)
10297
)
103-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
98+
s = normalise_output(str(v))
10499
# print(s)
105100
assert (
106101
'tests/test_expr_render.py:<line no> test_trailing_bracket\n'
107102
' foobar(1, 2, 3): 6 (int)'
108103
) == s
109104

110105

111-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
112106
def test_multiline():
113107
v = debug.format(
114108
foobar(1,
115109
2,
116110
3)
117111
)
118-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
112+
s = normalise_output(str(v))
119113
# print(s)
120114
assert (
121115
'tests/test_expr_render.py:<line no> test_multiline\n'
122116
' foobar(1, 2, 3): 6 (int)'
123117
) == s
124118

125119

126-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
127120
def test_multiline_trailing_bracket():
128121
v = debug.format(
129122
foobar(1, 2, 3
130123
))
131-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
124+
s = normalise_output(str(v))
132125
# print(s)
133126
assert (
134127
'tests/test_expr_render.py:<line no> test_multiline_trailing_bracket\n'
135128
' foobar(1, 2, 3 ): 6 (int)'
136129
) == s
137130

138131

139-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
140132
@pytest.mark.skipif(sys.version_info < (3, 6), reason='kwarg order is not guaranteed for 3.5')
141133
def test_kwargs():
142134
v = debug.format(
143135
foobar(1, 2, 3),
144136
a=6,
145137
b=7
146138
)
147-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
139+
s = normalise_output(str(v))
148140
assert (
149141
'tests/test_expr_render.py:<line no> test_kwargs\n'
150142
' foobar(1, 2, 3): 6 (int)\n'
@@ -153,7 +145,6 @@ def test_kwargs():
153145
) == s
154146

155147

156-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
157148
@pytest.mark.skipif(sys.version_info < (3, 6), reason='kwarg order is not guaranteed for 3.5')
158149
def test_kwargs_multiline():
159150
v = debug.format(
@@ -162,7 +153,7 @@ def test_kwargs_multiline():
162153
a=6,
163154
b=7
164155
)
165-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
156+
s = normalise_output(str(v))
166157
assert (
167158
'tests/test_expr_render.py:<line no> test_kwargs_multiline\n'
168159
' foobar(1, 2, 3): 6 (int)\n'
@@ -171,20 +162,18 @@ def test_kwargs_multiline():
171162
) == s
172163

173164

174-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
175165
def test_multiple_trailing_lines():
176166
v = debug.format(
177167
foobar(
178168
1, 2, 3
179169
),
180170
)
181-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
171+
s = normalise_output(str(v))
182172
assert (
183173
'tests/test_expr_render.py:<line no> test_multiple_trailing_lines\n foobar( 1, 2, 3 ): 6 (int)'
184174
) == s
185175

186176

187-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
188177
def test_very_nested_last_statement():
189178
def func():
190179
return debug.format(
@@ -201,14 +190,13 @@ def func():
201190

202191
v = func()
203192
# check only the original code is included in the warning
204-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
193+
s = normalise_output(str(v))
205194
assert s == (
206195
'tests/test_expr_render.py:<line no> func\n'
207196
' abs( abs( abs( abs( -1 ) ) ) ): 1 (int)'
208197
)
209198

210199

211-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
212200
def test_syntax_warning():
213201
def func():
214202
return debug.format(
@@ -227,7 +215,7 @@ def func():
227215

228216
v = func()
229217
# check only the original code is included in the warning
230-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
218+
s = normalise_output(str(v))
231219
assert s == (
232220
'tests/test_expr_render.py:<line no> func\n'
233221
' abs( abs( abs( abs( abs( -1 ) ) ) ) ): 1 (int)'
@@ -254,14 +242,13 @@ def func():
254242
)
255243

256244
v = func()
257-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
245+
s = normalise_output(str(v))
258246
assert s == (
259247
'tests/test_expr_render.py:<line no> func\n'
260248
' abs( abs( abs( abs( abs( -1 ) ) ) ) ): 1 (int)'
261249
)
262250

263251

264-
@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
265252
def test_await():
266253
async def foo():
267254
return 1
@@ -272,7 +259,7 @@ async def bar():
272259
loop = asyncio.new_event_loop()
273260
v = loop.run_until_complete(bar())
274261
loop.close()
275-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
262+
s = normalise_output(str(v))
276263
assert (
277264
'tests/test_expr_render.py:<line no> bar\n'
278265
' await foo(): 1 (int)'
@@ -284,7 +271,7 @@ def test_other_debug_arg():
284271
v = debug.format([1, 2])
285272

286273
# check only the original code is included in the warning
287-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
274+
s = normalise_output(str(v))
288275
assert s == (
289276
'tests/test_expr_render.py:<line no> test_other_debug_arg\n'
290277
' [1, 2] (list) len=2'
@@ -297,7 +284,7 @@ def test_other_debug_arg_not_literal():
297284
y = 2
298285
v = debug.format([x, y])
299286

300-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
287+
s = normalise_output(str(v))
301288
assert s == (
302289
'tests/test_expr_render.py:<line no> test_other_debug_arg_not_literal\n'
303290
' [x, y]: [1, 2] (list) len=2'
@@ -310,7 +297,7 @@ def test_executing_failure():
310297
y = 2
311298

312299
# executing fails inside a pytest assert ast the AST is modified
313-
assert re.sub(r':\d{2,}', ':<line no>', str(debug.format([x, y]))) == (
300+
assert normalise_output(str(debug.format([x, y]))) == (
314301
'tests/test_expr_render.py:<line no> test_executing_failure '
315302
'(executing failed to find the calling node)\n'
316303
' [1, 2] (list) len=2'
@@ -326,7 +313,7 @@ def test_format_inside_error():
326313
except RuntimeError as e:
327314
v = str(e)
328315

329-
s = re.sub(r':\d{2,}', ':<line no>', str(v))
316+
s = normalise_output(str(v))
330317
assert s == (
331318
'tests/test_expr_render.py:<line no> test_format_inside_error\n'
332319
' [x, y]: [1, 2] (list) len=2'

0 commit comments

Comments
 (0)