11import asyncio
2- import re
32import sys
43
54import pytest
65
76from devtools import Debug , debug
87
8+ from .utils import normalise_output
9+
910
1011def foobar (a , b , c ):
1112 return a + b + c
1213
1314
14- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
1515def 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' )
2726def 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' )
3836def 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' )
8783def 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' )
9994def 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' )
112106def 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' )
127120def 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' )
141133def 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' )
158149def 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' )
175165def 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' )
188177def 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' )
212200def 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' )
265252def 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