Show More
@@ -9,8 +9,6 b' from inspect import signature, Signature, Parameter' | |||
|
9 | 9 | import os |
|
10 | 10 | import re |
|
11 | 11 | |
|
12 | import nose.tools as nt | |
|
13 | ||
|
14 | 12 | from .. import oinspect |
|
15 | 13 | |
|
16 | 14 | from decorator import decorator |
@@ -38,7 +36,7 b' def setup_module():' | |||
|
38 | 36 | # defined, if any code is inserted above, the following line will need to be |
|
39 | 37 | # updated. Do NOT insert any whitespace between the next line and the function |
|
40 | 38 | # definition below. |
|
41 |
THIS_LINE_NUMBER = |
|
|
39 | THIS_LINE_NUMBER = 39 # Put here the actual number of this line | |
|
42 | 40 | |
|
43 | 41 | from unittest import TestCase |
|
44 | 42 | |
@@ -97,7 +95,7 b' def test_find_file_decorated2():' | |||
|
97 | 95 | |
|
98 | 96 | def test_find_file_magic(): |
|
99 | 97 | run = ip.find_line_magic('run') |
|
100 |
|
|
|
98 | assert oinspect.find_file(run) is not None | |
|
101 | 99 | |
|
102 | 100 | |
|
103 | 101 | # A few generic objects we can then inspect in the tests below |
@@ -169,11 +167,11 b' def test_info():' | |||
|
169 | 167 | "Check that Inspector.info fills out various fields as expected." |
|
170 | 168 | i = inspector.info(Call, oname="Call") |
|
171 | 169 | assert i["type_name"] == "type" |
|
172 | expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> | |
|
173 | assert i["base_class"] == expted_class | |
|
174 |
|
|
|
175 | i["string_form"], | |
|
170 | expected_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> | |
|
171 | assert i["base_class"] == expected_class | |
|
172 | assert re.search( | |
|
176 | 173 | "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>", |
|
174 | i["string_form"], | |
|
177 | 175 | ) |
|
178 | 176 | fname = __file__ |
|
179 | 177 | if fname.endswith(".pyc"): |
@@ -184,12 +182,12 b' def test_info():' | |||
|
184 | 182 | assert i["definition"] == None |
|
185 | 183 | assert i["docstring"] == Call.__doc__ |
|
186 | 184 | assert i["source"] == None |
|
187 |
|
|
|
185 | assert i["isclass"] is True | |
|
188 | 186 | assert i["init_definition"] == "Call(x, y=1)" |
|
189 | 187 | assert i["init_docstring"] == Call.__init__.__doc__ |
|
190 | 188 | |
|
191 | 189 | i = inspector.info(Call, detail_level=1) |
|
192 |
|
|
|
190 | assert i["source"] is not None | |
|
193 | 191 | assert i["docstring"] == None |
|
194 | 192 | |
|
195 | 193 | c = Call(1) |
@@ -221,7 +219,7 b' def test_info_serialliar():' | |||
|
221 | 219 | |
|
222 | 220 | # Nested attribute access should be cut off at 100 levels deep to avoid |
|
223 | 221 | # infinite loops: https://github.com/ipython/ipython/issues/9122 |
|
224 |
|
|
|
222 | assert fib_tracker[0] < 9000 | |
|
225 | 223 | |
|
226 | 224 | def support_function_one(x, y=2, *a, **kw): |
|
227 | 225 | """A simple function.""" |
@@ -230,7 +228,8 b' def test_calldef_none():' | |||
|
230 | 228 | # We should ignore __call__ for all of these. |
|
231 | 229 | for obj in [support_function_one, SimpleClass().method, any, str.upper]: |
|
232 | 230 | i = inspector.info(obj) |
|
233 |
|
|
|
231 | assert i["call_def"] is None | |
|
232 | ||
|
234 | 233 | |
|
235 | 234 | def f_kwarg(pos, *, kwonly): |
|
236 | 235 | pass |
@@ -266,7 +265,7 b' def test_getdoc():' | |||
|
266 | 265 | |
|
267 | 266 | def test_empty_property_has_no_source(): |
|
268 | 267 | i = inspector.info(property(), detail_level=1) |
|
269 |
|
|
|
268 | assert i["source"] is None | |
|
270 | 269 | |
|
271 | 270 | |
|
272 | 271 | def test_property_sources(): |
@@ -288,14 +287,14 b' def test_property_sources():' | |||
|
288 | 287 |
adder = property(simple_add) |
|
289 | 288 | |
|
290 | 289 | i = inspector.info(A.foo, detail_level=1) |
|
291 |
|
|
|
292 |
|
|
|
290 | assert "def foo(self):" in i["source"] | |
|
291 | assert "lambda self, v:" in i["source"] | |
|
293 | 292 | |
|
294 | 293 | i = inspector.info(A.dname, detail_level=1) |
|
295 |
|
|
|
294 | assert "def dirname(p)" in i["source"] | |
|
296 | 295 | |
|
297 | 296 | i = inspector.info(A.adder, detail_level=1) |
|
298 |
|
|
|
297 | assert "def simple_add(a, b)" in i["source"] | |
|
299 | 298 | |
|
300 | 299 | |
|
301 | 300 | def test_property_docstring_is_in_info_for_detail_level_0(): |
@@ -396,14 +395,14 b' def test_pinfo_magic():' | |||
|
396 | 395 | def test_init_colors(): |
|
397 | 396 | # ensure colors are not present in signature info |
|
398 | 397 | info = inspector.info(HasSignature) |
|
399 |
init_def = info[ |
|
|
400 |
|
|
|
398 | init_def = info["init_definition"] | |
|
399 | assert "[0m" not in init_def | |
|
401 | 400 | |
|
402 | 401 | |
|
403 | 402 | def test_builtin_init(): |
|
404 | 403 | info = inspector.info(list) |
|
405 | 404 | init_def = info['init_definition'] |
|
406 | nt.assert_is_not_none(init_def) | |
|
405 | assert init_def is not None | |
|
407 | 406 | |
|
408 | 407 | |
|
409 | 408 | def test_render_signature_short(): |
@@ -428,7 +427,7 b' def test_render_signature_long():' | |||
|
428 | 427 | signature(long_function), |
|
429 | 428 | long_function.__name__, |
|
430 | 429 | ) |
|
431 |
|
|
|
430 | assert sig in [ | |
|
432 | 431 | # Python >=3.9 |
|
433 | 432 | '''\ |
|
434 | 433 | long_function( |
@@ -452,4 +451,4 b' long_function(' | |||
|
452 | 451 | let_us_make_sure_this_is_looong:Union[str, NoneType]=None, |
|
453 | 452 | ) -> bool\ |
|
454 | 453 | ''', |
|
455 |
] |
|
|
454 | ] |
General Comments 0
You need to be logged in to leave comments.
Login now