Objects with _ipython_display_ defined bypass other formatters
()
| 460 | |
| 461 | |
| 462 | def test_ipython_display_formatter(): |
| 463 | """Objects with _ipython_display_ defined bypass other formatters""" |
| 464 | f = get_ipython().display_formatter |
| 465 | catcher = [] |
| 466 | |
| 467 | class SelfDisplaying(object): |
| 468 | def _ipython_display_(self): |
| 469 | catcher.append(self) |
| 470 | |
| 471 | class NotSelfDisplaying(object): |
| 472 | def __repr__(self): |
| 473 | return "NotSelfDisplaying" |
| 474 | |
| 475 | def _ipython_display_(self): |
| 476 | raise NotImplementedError |
| 477 | |
| 478 | save_enabled = f.ipython_display_formatter.enabled |
| 479 | f.ipython_display_formatter.enabled = True |
| 480 | |
| 481 | yes = SelfDisplaying() |
| 482 | no = NotSelfDisplaying() |
| 483 | |
| 484 | d, md = f.format(no) |
| 485 | assert d == {"text/plain": repr(no)} |
| 486 | assert md == {} |
| 487 | assert catcher == [] |
| 488 | |
| 489 | d, md = f.format(yes) |
| 490 | assert d == {} |
| 491 | assert md == {} |
| 492 | assert catcher == [yes] |
| 493 | |
| 494 | f.ipython_display_formatter.enabled = save_enabled |
| 495 | |
| 496 | |
| 497 | def test_repr_mime(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…