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

Function test_repr_mime

IPython/core/tests/test_formatters.py:438–472  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

436
437
438def test_repr_mime():
439 class HasReprMime(object):
440 def _repr_mimebundle_(self, include=None, exclude=None):
441 return {
442 'application/json+test.v2': {
443 'x': 'y'
444 },
445 'plain/text' : '<HasReprMime>',
446 'image/png' : 'i-overwrite'
447 }
448
449 def _repr_png_(self):
450 return 'should-be-overwritten'
451 def _repr_html_(self):
452 return '<b>hi!</b>'
453
454 f = get_ipython().display_formatter
455 html_f = f.formatters['text/html']
456 save_enabled = html_f.enabled
457 html_f.enabled = True
458 obj = HasReprMime()
459 d, md = f.format(obj)
460 html_f.enabled = save_enabled
461
462 nt.assert_equal(sorted(d), ['application/json+test.v2',
463 'image/png',
464 'plain/text',
465 'text/html',
466 'text/plain'])
467 nt.assert_equal(md, {})
468
469 d, md = f.format(obj, include={'image/png'})
470 nt.assert_equal(list(d.keys()), ['image/png'],
471 'Include should filter out even things from repr_mimebundle')
472 nt.assert_equal(d['image/png'], 'i-overwrite', '_repr_mimebundle_ take precedence')
473
474
475

Callers

nothing calls this directly

Calls 3

get_ipythonFunction · 0.90
HasReprMimeClass · 0.85
formatMethod · 0.45

Tested by

no test coverage detected