1
1
import re
2
2
import sys
3
+ from collections .abc import Generator
3
4
from pathlib import Path
4
5
from subprocess import PIPE , run
5
6
8
9
from devtools import Debug , debug
9
10
from devtools .ansi import strip_ansi
10
11
12
+ pytestmark = pytest .mark .xfail (sys .platform == 'win32' , reason = 'as yet unknown windows problem' )
13
+
11
14
12
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
13
15
def test_print (capsys ):
14
16
a = 1
15
17
b = 2
16
- debug (a , b )
18
+ result = debug (a , b )
17
19
stdout , stderr = capsys .readouterr ()
18
20
print (stdout )
19
21
assert re .sub (r':\d{2,}' , ':<line no>' , stdout ) == (
@@ -22,9 +24,44 @@ def test_print(capsys):
22
24
' b: 2 (int)\n '
23
25
)
24
26
assert stderr == ''
27
+ assert result == (1 , 2 )
28
+
29
+
30
+ def test_print_kwargs (capsys ):
31
+ a = 1
32
+ b = 2
33
+ result = debug (a , b , foo = [1 , 2 , 3 ])
34
+ stdout , stderr = capsys .readouterr ()
35
+ print (stdout )
36
+ assert re .sub (r':\d{2,}' , ':<line no>' , stdout ) == (
37
+ 'tests/test_main.py:<line no> test_print_kwargs\n '
38
+ ' a: 1 (int)\n '
39
+ ' b: 2 (int)\n '
40
+ ' foo: [1, 2, 3] (list) len=3\n '
41
+ )
42
+ assert stderr == ''
43
+ assert result == (1 , 2 , {'foo' : [1 , 2 , 3 ]})
44
+
45
+
46
+ def test_print_generator (capsys ):
47
+ gen = (i for i in [1 , 2 ])
48
+
49
+ result = debug (gen )
50
+ stdout , stderr = capsys .readouterr ()
51
+ print (stdout )
52
+ assert re .sub (r':\d{2,}' , ':<line no>' , stdout ) == (
53
+ 'tests/test_main.py:<line no> test_print_generator\n '
54
+ ' gen: (\n '
55
+ ' 1,\n '
56
+ ' 2,\n '
57
+ ' ) (generator)\n '
58
+ )
59
+ assert stderr == ''
60
+ assert isinstance (result , Generator )
61
+ # the generator got evaluated and is now empty, that's correct currently
62
+ assert list (result ) == []
25
63
26
64
27
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
28
65
def test_format ():
29
66
a = b'i might bite'
30
67
b = "hello this is a test"
@@ -38,7 +75,6 @@ def test_format():
38
75
)
39
76
40
77
41
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
42
78
def test_print_subprocess (tmpdir ):
43
79
f = tmpdir .join ('test.py' )
44
80
f .write ("""\
@@ -68,7 +104,6 @@ def test_func(v):
68
104
)
69
105
70
106
71
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
72
107
def test_odd_path (mocker ):
73
108
# all valid calls
74
109
mocked_relative_to = mocker .patch ('pathlib.Path.relative_to' )
@@ -92,7 +127,6 @@ def test_small_call_frame():
92
127
)
93
128
94
129
95
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
96
130
def test_small_call_frame_warning ():
97
131
debug_ = Debug ()
98
132
v = debug_ .format (
@@ -109,7 +143,6 @@ def test_small_call_frame_warning():
109
143
)
110
144
111
145
112
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
113
146
@pytest .mark .skipif (sys .version_info < (3 , 6 ), reason = 'kwarg order is not guaranteed for 3.5' )
114
147
def test_kwargs ():
115
148
a = 'variable'
@@ -123,7 +156,6 @@ def test_kwargs():
123
156
)
124
157
125
158
126
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
127
159
def test_kwargs_orderless ():
128
160
# for python3.5
129
161
a = 'variable'
@@ -136,7 +168,6 @@ def test_kwargs_orderless():
136
168
}
137
169
138
170
139
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
140
171
def test_simple_vars ():
141
172
v = debug .format ('test' , 1 , 2 )
142
173
s = re .sub (r':\d{2,}' , ':<line no>' , str (v ))
@@ -206,7 +237,6 @@ def test_exec(capsys):
206
237
assert stderr == ''
207
238
208
239
209
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
210
240
def test_colours ():
211
241
v = debug .format (range (6 ))
212
242
s = re .sub (r':\d{2,}' , ':<line no>' , v .str (True ))
@@ -240,7 +270,6 @@ def test_breakpoint(mocker):
240
270
assert mocked_set_trace .called
241
271
242
272
243
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
244
273
def test_starred_kwargs ():
245
274
v = {'foo' : 1 , 'bar' : 2 }
246
275
v = debug .format (** v )
@@ -252,7 +281,6 @@ def test_starred_kwargs():
252
281
}
253
282
254
283
255
- @pytest .mark .xfail (sys .platform == 'win32' , reason = 'yet unknown windows problem' )
256
284
@pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = 'error repr different before 3.7' )
257
285
def test_pretty_error ():
258
286
class BadPretty :
@@ -279,3 +307,12 @@ def test_multiple_debugs():
279
307
'tests/test_main.py:<line no> test_multiple_debugs\n '
280
308
' [i * 2 for i in range(2)]: [0, 2] (list) len=2'
281
309
)
310
+
311
+
312
+ def test_return_args (capsys ):
313
+ assert debug ('foo' ) == 'foo'
314
+ assert debug ('foo' , 'bar' ) == ('foo' , 'bar' )
315
+ assert debug ('foo' , 'bar' , spam = 123 ) == ('foo' , 'bar' , {'spam' : 123 })
316
+ assert debug (spam = 123 ) == ({'spam' : 123 },)
317
+ stdout , stderr = capsys .readouterr ()
318
+ print (stdout )
0 commit comments