Show More
@@ -10,7 +10,8 b' import nose.tools as nt' | |||||
10 |
|
10 | |||
11 | from IPython.config import Config |
|
11 | from IPython.config import Config | |
12 | from IPython.core.formatters import ( |
|
12 | from IPython.core.formatters import ( | |
13 | PlainTextFormatter, HTMLFormatter, PDFFormatter, _mod_name_key |
|
13 | PlainTextFormatter, HTMLFormatter, PDFFormatter, _mod_name_key, | |
|
14 | DisplayFormatter, | |||
14 | ) |
|
15 | ) | |
15 | from IPython.utils.io import capture_output |
|
16 | from IPython.utils.io import capture_output | |
16 |
|
17 | |||
@@ -387,3 +388,33 b' def test_pretty_max_seq_length():' | |||||
387 | text = f(list(range(1024))) |
|
388 | text = f(list(range(1024))) | |
388 | lines = text.splitlines() |
|
389 | lines = text.splitlines() | |
389 | nt.assert_equal(len(lines), 1024) |
|
390 | nt.assert_equal(len(lines), 1024) | |
|
391 | ||||
|
392 | ||||
|
393 | def test_ipython_display_formatter(): | |||
|
394 | """Objects with _ipython_display_ defined bypass other formatters""" | |||
|
395 | f = get_ipython().display_formatter | |||
|
396 | catcher = [] | |||
|
397 | class SelfDisplaying(object): | |||
|
398 | def _ipython_display_(self): | |||
|
399 | catcher.append(self) | |||
|
400 | ||||
|
401 | class NotSelfDisplaying(object): | |||
|
402 | def __repr__(self): | |||
|
403 | return "NotSelfDisplaying" | |||
|
404 | ||||
|
405 | def _ipython_display_(self): | |||
|
406 | raise NotImplementedError | |||
|
407 | ||||
|
408 | yes = SelfDisplaying() | |||
|
409 | no = NotSelfDisplaying() | |||
|
410 | ||||
|
411 | d, md = f.format(no) | |||
|
412 | nt.assert_equal(d, {'text/plain': repr(no)}) | |||
|
413 | nt.assert_equal(md, {}) | |||
|
414 | nt.assert_equal(catcher, []) | |||
|
415 | ||||
|
416 | d, md = f.format(yes) | |||
|
417 | nt.assert_equal(d, {}) | |||
|
418 | nt.assert_equal(md, {}) | |||
|
419 | nt.assert_equal(catcher, [yes]) | |||
|
420 |
General Comments 0
You need to be logged in to leave comments.
Login now