MCPcopy Index your code
hub / github.com/ipython/ipython / test_ipython_display_formatter

Function test_ipython_display_formatter

tests/test_formatters.py:462–494  ·  view source on GitHub ↗

Objects with _ipython_display_ defined bypass other formatters

()

Source from the content-addressed store, hash-verified

460
461
462def 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
497def test_repr_mime():

Callers

nothing calls this directly

Calls 4

get_ipythonFunction · 0.90
SelfDisplayingClass · 0.85
NotSelfDisplayingClass · 0.85
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…