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

Function test_repr_mime

tests/test_formatters.py:497–534  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

495
496
497def test_repr_mime():
498 class HasReprMime(object):
499 def _repr_mimebundle_(self, include=None, exclude=None):
500 return {
501 "application/json+test.v2": {"x": "y"},
502 "plain/text": "<HasReprMime>",
503 "image/png": "i-overwrite",
504 }
505
506 def _repr_png_(self):
507 return "should-be-overwritten"
508
509 def _repr_html_(self):
510 return "<b>hi!</b>"
511
512 f = get_ipython().display_formatter
513 html_f = f.formatters["text/html"]
514 save_enabled = html_f.enabled
515 html_f.enabled = True
516 obj = HasReprMime()
517 d, md = f.format(obj)
518 html_f.enabled = save_enabled
519
520 assert sorted(d) == [
521 "application/json+test.v2",
522 "image/png",
523 "plain/text",
524 "text/html",
525 "text/plain",
526 ]
527 assert md == {}
528
529 d, md = f.format(obj, include={"image/png"})
530 assert list(d.keys()) == [
531 "image/png"
532 ], "Include should filter out even things from repr_mimebundle"
533
534 assert d["image/png"] == "i-overwrite", "_repr_mimebundle_ take precedence"
535
536
537def test_pass_correct_include_exclude():

Callers

nothing calls this directly

Calls 4

get_ipythonFunction · 0.90
HasReprMimeClass · 0.85
keysMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…