1
1
import asyncio
2
- import re
3
2
import sys
4
3
5
4
import pytest
6
5
7
6
from devtools import Debug , debug
8
7
8
+ from .utils import normalise_output
9
+
9
10
10
11
def foobar (a , b , c ):
11
12
return a + b + c
12
13
13
14
14
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
15
15
def test_simple ():
16
16
a = [1 , 2 , 3 ]
17
17
v = debug .format (len (a ))
18
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
18
+ s = normalise_output ( str (v ))
19
19
# print(s)
20
20
assert (
21
21
'tests/test_expr_render.py:<line no> test_simple\n '
22
22
' len(a): 3 (int)'
23
23
) == s
24
24
25
25
26
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
27
26
def test_subscription ():
28
27
a = {1 : 2 }
29
28
v = debug .format (a [1 ])
30
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
29
+ s = normalise_output ( str (v ))
31
30
assert (
32
31
'tests/test_expr_render.py:<line no> test_subscription\n '
33
32
' a[1]: 2 (int)'
34
33
) == s
35
34
36
35
37
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
38
36
def test_exotic_types ():
39
37
aa = [1 , 2 , 3 ]
40
38
v = debug .format (
@@ -49,8 +47,7 @@ def test_exotic_types():
49
47
{a : a + 1 for a in aa },
50
48
(a for a in aa ),
51
49
)
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 ))
54
51
print ('\n ---\n {}\n ---' .format (v ))
55
52
56
53
# Generator expression source changed in 3.8 to include parentheses, see:
@@ -83,68 +80,63 @@ def test_exotic_types():
83
80
) == s
84
81
85
82
86
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
87
83
def test_newline ():
88
84
v = debug .format (
89
85
foobar (1 , 2 , 3 ))
90
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
86
+ s = normalise_output ( str (v ))
91
87
# print(s)
92
88
assert (
93
89
'tests/test_expr_render.py:<line no> test_newline\n '
94
90
' foobar(1, 2, 3): 6 (int)'
95
91
) == s
96
92
97
93
98
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
99
94
def test_trailing_bracket ():
100
95
v = debug .format (
101
96
foobar (1 , 2 , 3 )
102
97
)
103
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
98
+ s = normalise_output ( str (v ))
104
99
# print(s)
105
100
assert (
106
101
'tests/test_expr_render.py:<line no> test_trailing_bracket\n '
107
102
' foobar(1, 2, 3): 6 (int)'
108
103
) == s
109
104
110
105
111
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
112
106
def test_multiline ():
113
107
v = debug .format (
114
108
foobar (1 ,
115
109
2 ,
116
110
3 )
117
111
)
118
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
112
+ s = normalise_output ( str (v ))
119
113
# print(s)
120
114
assert (
121
115
'tests/test_expr_render.py:<line no> test_multiline\n '
122
116
' foobar(1, 2, 3): 6 (int)'
123
117
) == s
124
118
125
119
126
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
127
120
def test_multiline_trailing_bracket ():
128
121
v = debug .format (
129
122
foobar (1 , 2 , 3
130
123
))
131
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
124
+ s = normalise_output ( str (v ))
132
125
# print(s)
133
126
assert (
134
127
'tests/test_expr_render.py:<line no> test_multiline_trailing_bracket\n '
135
128
' foobar(1, 2, 3 ): 6 (int)'
136
129
) == s
137
130
138
131
139
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
140
132
@pytest .mark .skipif (sys .version_info < (3 , 6 ), reason = 'kwarg order is not guaranteed for 3.5' )
141
133
def test_kwargs ():
142
134
v = debug .format (
143
135
foobar (1 , 2 , 3 ),
144
136
a = 6 ,
145
137
b = 7
146
138
)
147
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
139
+ s = normalise_output ( str (v ))
148
140
assert (
149
141
'tests/test_expr_render.py:<line no> test_kwargs\n '
150
142
' foobar(1, 2, 3): 6 (int)\n '
@@ -153,7 +145,6 @@ def test_kwargs():
153
145
) == s
154
146
155
147
156
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
157
148
@pytest .mark .skipif (sys .version_info < (3 , 6 ), reason = 'kwarg order is not guaranteed for 3.5' )
158
149
def test_kwargs_multiline ():
159
150
v = debug .format (
@@ -162,7 +153,7 @@ def test_kwargs_multiline():
162
153
a = 6 ,
163
154
b = 7
164
155
)
165
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
156
+ s = normalise_output ( str (v ))
166
157
assert (
167
158
'tests/test_expr_render.py:<line no> test_kwargs_multiline\n '
168
159
' foobar(1, 2, 3): 6 (int)\n '
@@ -171,20 +162,18 @@ def test_kwargs_multiline():
171
162
) == s
172
163
173
164
174
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
175
165
def test_multiple_trailing_lines ():
176
166
v = debug .format (
177
167
foobar (
178
168
1 , 2 , 3
179
169
),
180
170
)
181
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
171
+ s = normalise_output ( str (v ))
182
172
assert (
183
173
'tests/test_expr_render.py:<line no> test_multiple_trailing_lines\n foobar( 1, 2, 3 ): 6 (int)'
184
174
) == s
185
175
186
176
187
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
188
177
def test_very_nested_last_statement ():
189
178
def func ():
190
179
return debug .format (
@@ -201,14 +190,13 @@ def func():
201
190
202
191
v = func ()
203
192
# 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 ))
205
194
assert s == (
206
195
'tests/test_expr_render.py:<line no> func\n '
207
196
' abs( abs( abs( abs( -1 ) ) ) ): 1 (int)'
208
197
)
209
198
210
199
211
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
212
200
def test_syntax_warning ():
213
201
def func ():
214
202
return debug .format (
@@ -227,7 +215,7 @@ def func():
227
215
228
216
v = func ()
229
217
# 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 ))
231
219
assert s == (
232
220
'tests/test_expr_render.py:<line no> func\n '
233
221
' abs( abs( abs( abs( abs( -1 ) ) ) ) ): 1 (int)'
@@ -254,14 +242,13 @@ def func():
254
242
)
255
243
256
244
v = func ()
257
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
245
+ s = normalise_output ( str (v ))
258
246
assert s == (
259
247
'tests/test_expr_render.py:<line no> func\n '
260
248
' abs( abs( abs( abs( abs( -1 ) ) ) ) ): 1 (int)'
261
249
)
262
250
263
251
264
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
265
252
def test_await ():
266
253
async def foo ():
267
254
return 1
@@ -272,7 +259,7 @@ async def bar():
272
259
loop = asyncio .new_event_loop ()
273
260
v = loop .run_until_complete (bar ())
274
261
loop .close ()
275
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
262
+ s = normalise_output ( str (v ))
276
263
assert (
277
264
'tests/test_expr_render.py:<line no> bar\n '
278
265
' await foo(): 1 (int)'
@@ -284,7 +271,7 @@ def test_other_debug_arg():
284
271
v = debug .format ([1 , 2 ])
285
272
286
273
# 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 ))
288
275
assert s == (
289
276
'tests/test_expr_render.py:<line no> test_other_debug_arg\n '
290
277
' [1, 2] (list) len=2'
@@ -297,7 +284,7 @@ def test_other_debug_arg_not_literal():
297
284
y = 2
298
285
v = debug .format ([x , y ])
299
286
300
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
287
+ s = normalise_output ( str (v ))
301
288
assert s == (
302
289
'tests/test_expr_render.py:<line no> test_other_debug_arg_not_literal\n '
303
290
' [x, y]: [1, 2] (list) len=2'
@@ -310,7 +297,7 @@ def test_executing_failure():
310
297
y = 2
311
298
312
299
# 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 ]))) == (
314
301
'tests/test_expr_render.py:<line no> test_executing_failure '
315
302
'(executing failed to find the calling node)\n '
316
303
' [1, 2] (list) len=2'
@@ -326,7 +313,7 @@ def test_format_inside_error():
326
313
except RuntimeError as e :
327
314
v = str (e )
328
315
329
- s = re . sub ( r':\d{2,}' , ':<line no>' , str (v ))
316
+ s = normalise_output ( str (v ))
330
317
assert s == (
331
318
'tests/test_expr_render.py:<line no> test_format_inside_error\n '
332
319
' [x, y]: [1, 2] (list) len=2'
0 commit comments