38
38
reason = "rendered differently on py3.10" ,
39
39
)
40
40
41
+ skip_py311 = pytest .mark .skipif (
42
+ sys .version_info .minor == 11 and sys .version_info .major == 3 ,
43
+ reason = "rendered differently on py3.11" ,
44
+ )
45
+
41
46
skip_pypy3 = pytest .mark .skipif (
42
47
hasattr (sys , "pypy_version_info" ),
43
48
reason = "rendered differently on pypy3" ,
@@ -93,23 +98,24 @@ def test_render():
93
98
result = console .file .getvalue ()
94
99
print (repr (result ))
95
100
expected = "╭────────────── <class 'tests.test_inspect.Foo'> ──────────────╮\n │ Foo test │\n │ │\n │ broken = InspectError() │\n │ __init__ = def __init__(foo: int) -> None: constructor docs. │\n │ method = def method(a, b) -> str: Multi line │\n ╰──────────────────────────────────────────────────────────────╯\n "
96
- assert expected == result
101
+ assert result == expected
97
102
98
103
99
104
@skip_pypy3
100
105
def test_inspect_text ():
106
+ num_attributes = 34 if sys .version_info >= (3 , 11 ) else 33
101
107
expected = (
102
108
"╭──────────────── <class 'str'> ─────────────────╮\n "
103
109
"│ str(object='') -> str │\n "
104
110
"│ str(bytes_or_buffer[, encoding[, errors]]) -> │\n "
105
111
"│ str │\n "
106
112
"│ │\n "
107
- "│ 33 attribute(s) not shown. Run │\n "
113
+ f "│ { num_attributes } attribute(s) not shown. Run │\n "
108
114
"│ inspect(inspect) for options. │\n "
109
115
"╰────────────────────────────────────────────────╯\n "
110
116
)
111
117
print (repr (expected ))
112
- assert expected == render ("Hello" )
118
+ assert render ("Hello" ) == expected
113
119
114
120
115
121
@skip_py36
@@ -136,8 +142,10 @@ def test_inspect_empty_dict():
136
142
assert render ({}).startswith (expected )
137
143
138
144
145
+ @skip_py311
139
146
@skip_pypy3
140
- def test_inspect_builtin_function ():
147
+ def test_inspect_builtin_function_except_python311 ():
148
+ # Pre-3.11 Python versions - print builtin has no signature available
141
149
expected = (
142
150
"╭────────── <built-in function print> ───────────╮\n "
143
151
"│ def print(...) │\n "
@@ -149,7 +157,28 @@ def test_inspect_builtin_function():
149
157
"│ inspect(inspect) for options. │\n "
150
158
"╰────────────────────────────────────────────────╯\n "
151
159
)
152
- assert expected == render (print )
160
+ assert render (print ) == expected
161
+
162
+
163
+ @pytest .mark .skipif (
164
+ sys .version_info < (3 , 11 ), reason = "print builtin signature only available on 3.11+"
165
+ )
166
+ @skip_pypy3
167
+ def test_inspect_builtin_function_only_python311 ():
168
+ # On 3.11, the print builtin *does* have a signature, unlike in prior versions
169
+ expected = (
170
+ "╭────────── <built-in function print> ───────────╮\n "
171
+ "│ def print(*args, sep=' ', end='\\ n', file=None, │\n "
172
+ "│ flush=False): │\n "
173
+ "│ │\n "
174
+ "│ Prints the values to a stream, or to │\n "
175
+ "│ sys.stdout by default. │\n "
176
+ "│ │\n "
177
+ "│ 30 attribute(s) not shown. Run │\n "
178
+ "│ inspect(inspect) for options. │\n "
179
+ "╰────────────────────────────────────────────────╯\n "
180
+ )
181
+ assert render (print ) == expected
153
182
154
183
155
184
@skip_pypy3
@@ -186,13 +215,14 @@ def test_inspect_integer_with_value():
186
215
expected = "╭────── <class 'int'> ───────╮\n │ int([x]) -> integer │\n │ int(x, base=10) -> integer │\n │ │\n │ ╭────────────────────────╮ │\n │ │ 1 │ │\n │ ╰────────────────────────╯ │\n │ │\n │ denominator = 1 │\n │ imag = 0 │\n │ numerator = 1 │\n │ real = 1 │\n ╰────────────────────────────╯\n "
187
216
value = render (1 , value = True )
188
217
print (repr (value ))
189
- assert expected == value
218
+ assert value == expected
190
219
191
220
192
221
@skip_py36
193
222
@skip_py37
194
223
@skip_py310
195
- def test_inspect_integer_with_methods ():
224
+ @skip_py311
225
+ def test_inspect_integer_with_methods_python38_and_python39 ():
196
226
expected = (
197
227
"╭──────────────── <class 'int'> ─────────────────╮\n "
198
228
"│ int([x]) -> integer │\n "
@@ -222,14 +252,15 @@ def test_inspect_integer_with_methods():
222
252
"│ an integer. │\n "
223
253
"╰────────────────────────────────────────────────╯\n "
224
254
)
225
- assert expected == render (1 , methods = True )
255
+ assert render (1 , methods = True ) == expected
226
256
227
257
228
258
@skip_py36
229
259
@skip_py37
230
260
@skip_py38
231
261
@skip_py39
232
- def test_inspect_integer_with_methods ():
262
+ @skip_py311
263
+ def test_inspect_integer_with_methods_python310only ():
233
264
expected = (
234
265
"╭──────────────── <class 'int'> ─────────────────╮\n "
235
266
"│ int([x]) -> integer │\n "
@@ -263,7 +294,51 @@ def test_inspect_integer_with_methods():
263
294
"│ an integer. │\n "
264
295
"╰────────────────────────────────────────────────╯\n "
265
296
)
266
- assert expected == render (1 , methods = True )
297
+ assert render (1 , methods = True ) == expected
298
+
299
+
300
+ @skip_py36
301
+ @skip_py37
302
+ @skip_py38
303
+ @skip_py39
304
+ @skip_py310
305
+ def test_inspect_integer_with_methods_python311_and_above ():
306
+ # to_bytes and from_bytes methods on int had minor signature change -
307
+ # they now, as of 3.11, have default values for all of their parameters
308
+ expected = (
309
+ "╭──────────────── <class 'int'> ─────────────────╮\n "
310
+ "│ int([x]) -> integer │\n "
311
+ "│ int(x, base=10) -> integer │\n "
312
+ "│ │\n "
313
+ "│ denominator = 1 │\n "
314
+ "│ imag = 0 │\n "
315
+ "│ numerator = 1 │\n "
316
+ "│ real = 1 │\n "
317
+ "│ as_integer_ratio = def as_integer_ratio(): │\n "
318
+ "│ Return integer ratio. │\n "
319
+ "│ bit_count = def bit_count(): Number of │\n "
320
+ "│ ones in the binary │\n "
321
+ "│ representation of the │\n "
322
+ "│ absolute value of self. │\n "
323
+ "│ bit_length = def bit_length(): Number of │\n "
324
+ "│ bits necessary to represent │\n "
325
+ "│ self in binary. │\n "
326
+ "│ conjugate = def conjugate(...) Returns │\n "
327
+ "│ self, the complex conjugate │\n "
328
+ "│ of any int. │\n "
329
+ "│ from_bytes = def from_bytes(bytes, │\n "
330
+ "│ byteorder='big', *, │\n "
331
+ "│ signed=False): Return the │\n "
332
+ "│ integer represented by the │\n "
333
+ "│ given array of bytes. │\n "
334
+ "│ to_bytes = def to_bytes(length=1, │\n "
335
+ "│ byteorder='big', *, │\n "
336
+ "│ signed=False): Return an │\n "
337
+ "│ array of bytes representing │\n "
338
+ "│ an integer. │\n "
339
+ "╰────────────────────────────────────────────────╯\n "
340
+ )
341
+ assert render (1 , methods = True ) == expected
267
342
268
343
269
344
@skip_py36
@@ -387,8 +462,10 @@ def test_object_types_mro(obj: object, expected_result: Sequence[Type]):
387
462
[str , ["builtins.str" , "builtins.object" ]],
388
463
[Foo (1 ), [f"{ __name__ } .Foo" , "builtins.object" ]],
389
464
[Foo , [f"{ __name__ } .Foo" , "builtins.object" ]],
390
- [FooSubclass (1 ), [f"{ __name__ } .FooSubclass" , f"{ __name__ } .Foo" , "builtins.object" ]],
391
- [FooSubclass , [f"{ __name__ } .FooSubclass" , f"{ __name__ } .Foo" , "builtins.object" ]],
465
+ [FooSubclass (1 ),
466
+ [f"{ __name__ } .FooSubclass" , f"{ __name__ } .Foo" , "builtins.object" ]],
467
+ [FooSubclass ,
468
+ [f"{ __name__ } .FooSubclass" , f"{ __name__ } .Foo" , "builtins.object" ]],
392
469
# fmt: on
393
470
),
394
471
)
0 commit comments