MCPcopy Create free account
hub / github.com/ipython/ipython / test_ipython_display_formatter

Function test_ipython_display_formatter

IPython/core/tests/test_formatters.py:392–423  ·  view source on GitHub ↗

Objects with _ipython_display_ defined bypass other formatters

()

Source from the content-addressed store, hash-verified

390
391
392def 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
426def test_json_as_string_deprecated():

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