Objects with _ipython_display_ defined bypass other formatters
()
| 390 | |
| 391 | |
| 392 | def test_ipython_display_formatter(): |
| 393 | """Objects with _ipython_display_ defined bypass other formatters""" |
| 394 | f = get_ipython().display_formatter |
| 395 | catcher = [] |
| 396 | class SelfDisplaying(object): |
| 397 | def _ipython_display_(self): |
| 398 | catcher.append(self) |
| 399 | |
| 400 | class NotSelfDisplaying(object): |
| 401 | def __repr__(self): |
| 402 | return "NotSelfDisplaying" |
| 403 | |
| 404 | def _ipython_display_(self): |
| 405 | raise NotImplementedError |
| 406 | |
| 407 | save_enabled = f.ipython_display_formatter.enabled |
| 408 | f.ipython_display_formatter.enabled = True |
| 409 | |
| 410 | yes = SelfDisplaying() |
| 411 | no = NotSelfDisplaying() |
| 412 | |
| 413 | d, md = f.format(no) |
| 414 | nt.assert_equal(d, {'text/plain': repr(no)}) |
| 415 | nt.assert_equal(md, {}) |
| 416 | nt.assert_equal(catcher, []) |
| 417 | |
| 418 | d, md = f.format(yes) |
| 419 | nt.assert_equal(d, {}) |
| 420 | nt.assert_equal(md, {}) |
| 421 | nt.assert_equal(catcher, [yes]) |
| 422 | |
| 423 | f.ipython_display_formatter.enabled = save_enabled |
| 424 | |
| 425 | |
| 426 | def test_json_as_string_deprecated(): |
nothing calls this directly
no test coverage detected