Show More
@@ -56,7 +56,7 b' def pyfile(fname):' | |||||
56 |
|
56 | |||
57 |
|
57 | |||
58 | def match_pyfiles(f1, f2): |
|
58 | def match_pyfiles(f1, f2): | |
59 |
|
|
59 | assert pyfile(f1) == pyfile(f2) | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | def test_find_file(): |
|
62 | def test_find_file(): | |
@@ -76,7 +76,7 b' def test_find_file_decorated1():' | |||||
76 | "My docstring" |
|
76 | "My docstring" | |
77 |
|
77 | |||
78 | match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__)) |
|
78 | match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__)) | |
79 |
|
|
79 | assert f.__doc__ == "My docstring" | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | def test_find_file_decorated2(): |
|
82 | def test_find_file_decorated2(): | |
@@ -92,7 +92,7 b' def test_find_file_decorated2():' | |||||
92 | "My docstring 2" |
|
92 | "My docstring 2" | |
93 |
|
93 | |||
94 | match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__)) |
|
94 | match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__)) | |
95 |
|
|
95 | assert f.__doc__ == "My docstring 2" | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | def test_find_file_magic(): |
|
98 | def test_find_file_magic(): | |
@@ -167,41 +167,46 b' class SerialLiar(object):' | |||||
167 |
|
167 | |||
168 | def test_info(): |
|
168 | def test_info(): | |
169 | "Check that Inspector.info fills out various fields as expected." |
|
169 | "Check that Inspector.info fills out various fields as expected." | |
170 |
i = inspector.info(Call, oname= |
|
170 | i = inspector.info(Call, oname="Call") | |
171 |
|
|
171 | assert i["type_name"] == "type" | |
172 | expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> |
|
172 | expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> | |
173 |
|
|
173 | assert i["base_class"] == expted_class | |
174 | nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>") |
|
174 | nt.assert_regex( | |
|
175 | i["string_form"], | |||
|
176 | "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>", | |||
|
177 | ) | |||
175 | fname = __file__ |
|
178 | fname = __file__ | |
176 | if fname.endswith(".pyc"): |
|
179 | if fname.endswith(".pyc"): | |
177 | fname = fname[:-1] |
|
180 | fname = fname[:-1] | |
178 | # case-insensitive comparison needed on some filesystems |
|
181 | # case-insensitive comparison needed on some filesystems | |
179 | # e.g. Windows: |
|
182 | # e.g. Windows: | |
180 |
|
|
183 | assert i["file"].lower() == compress_user(fname).lower() | |
181 |
|
|
184 | assert i["definition"] == None | |
182 |
|
|
185 | assert i["docstring"] == Call.__doc__ | |
183 |
|
|
186 | assert i["source"] == None | |
184 |
nt.assert_true(i[ |
|
187 | nt.assert_true(i["isclass"]) | |
185 |
|
|
188 | assert i["init_definition"] == "Call(x, y=1)" | |
186 |
|
|
189 | assert i["init_docstring"] == Call.__init__.__doc__ | |
187 |
|
190 | |||
188 | i = inspector.info(Call, detail_level=1) |
|
191 | i = inspector.info(Call, detail_level=1) | |
189 |
nt.assert_not_equal(i[ |
|
192 | nt.assert_not_equal(i["source"], None) | |
190 |
|
|
193 | assert i["docstring"] == None | |
191 |
|
194 | |||
192 | c = Call(1) |
|
195 | c = Call(1) | |
193 | c.__doc__ = "Modified instance docstring" |
|
196 | c.__doc__ = "Modified instance docstring" | |
194 | i = inspector.info(c) |
|
197 | i = inspector.info(c) | |
195 |
|
|
198 | assert i["type_name"] == "Call" | |
196 |
|
|
199 | assert i["docstring"] == "Modified instance docstring" | |
197 |
|
|
200 | assert i["class_docstring"] == Call.__doc__ | |
198 |
|
|
201 | assert i["init_docstring"] == Call.__init__.__doc__ | |
199 |
|
|
202 | assert i["call_docstring"] == Call.__call__.__doc__ | |
|
203 | ||||
200 |
|
204 | |||
201 | def test_class_signature(): |
|
205 | def test_class_signature(): | |
202 |
info = inspector.info(HasSignature, |
|
206 | info = inspector.info(HasSignature, "HasSignature") | |
203 |
|
|
207 | assert info["init_definition"] == "HasSignature(test)" | |
204 |
|
|
208 | assert info["init_docstring"] == HasSignature.__init__.__doc__ | |
|
209 | ||||
205 |
|
210 | |||
206 | def test_info_awkward(): |
|
211 | def test_info_awkward(): | |
207 | # Just test that this doesn't throw an error. |
|
212 | # Just test that this doesn't throw an error. | |
@@ -231,8 +236,9 b' def f_kwarg(pos, *, kwonly):' | |||||
231 | pass |
|
236 | pass | |
232 |
|
237 | |||
233 | def test_definition_kwonlyargs(): |
|
238 | def test_definition_kwonlyargs(): | |
234 |
i = inspector.info(f_kwarg, oname= |
|
239 | i = inspector.info(f_kwarg, oname="f_kwarg") # analysis:ignore | |
235 |
|
|
240 | assert i["definition"] == "f_kwarg(pos, *, kwonly)" | |
|
241 | ||||
236 |
|
242 | |||
237 | def test_getdoc(): |
|
243 | def test_getdoc(): | |
238 | class A(object): |
|
244 | class A(object): | |
@@ -253,9 +259,9 b' def test_getdoc():' | |||||
253 | b = B() |
|
259 | b = B() | |
254 | c = C() |
|
260 | c = C() | |
255 |
|
261 | |||
256 |
|
|
262 | assert oinspect.getdoc(a) == "standard docstring" | |
257 |
|
|
263 | assert oinspect.getdoc(b) == "custom docstring" | |
258 |
|
|
264 | assert oinspect.getdoc(c) == "standard docstring" | |
259 |
|
265 | |||
260 |
|
266 | |||
261 | def test_empty_property_has_no_source(): |
|
267 | def test_empty_property_has_no_source(): | |
@@ -299,15 +305,17 b' def test_property_docstring_is_in_info_for_detail_level_0():' | |||||
299 | """This is `foobar` property.""" |
|
305 | """This is `foobar` property.""" | |
300 | pass |
|
306 | pass | |
301 |
|
307 | |||
302 |
ip.user_ns[ |
|
308 | ip.user_ns["a_obj"] = A() | |
303 |
|
|
309 | assert ( | |
304 |
|
|
310 | "This is `foobar` property." | |
305 |
ip.object_inspect( |
|
311 | == ip.object_inspect("a_obj.foobar", detail_level=0)["docstring"] | |
|
312 | ) | |||
306 |
|
313 | |||
307 |
ip.user_ns[ |
|
314 | ip.user_ns["a_cls"] = A | |
308 |
|
|
315 | assert ( | |
309 |
|
|
316 | "This is `foobar` property." | |
310 |
ip.object_inspect( |
|
317 | == ip.object_inspect("a_cls.foobar", detail_level=0)["docstring"] | |
|
318 | ) | |||
311 |
|
319 | |||
312 |
|
320 | |||
313 | def test_pdef(): |
|
321 | def test_pdef(): | |
@@ -404,7 +412,7 b' def test_render_signature_short():' | |||||
404 | signature(short_fun), |
|
412 | signature(short_fun), | |
405 | short_fun.__name__, |
|
413 | short_fun.__name__, | |
406 | ) |
|
414 | ) | |
407 |
|
|
415 | assert sig == "short_fun(a=1)" | |
408 |
|
416 | |||
409 |
|
417 | |||
410 | def test_render_signature_long(): |
|
418 | def test_render_signature_long(): |
General Comments 0
You need to be logged in to leave comments.
Login now