Show More
@@ -26,6 +26,7 b' Authors:' | |||
|
26 | 26 | # Stdlib imports |
|
27 | 27 | import abc |
|
28 | 28 | import sys |
|
29 | import types | |
|
29 | 30 | import warnings |
|
30 | 31 | |
|
31 | 32 | from IPython.external.decorator import decorator |
@@ -312,7 +313,8 b' class BaseFormatter(Configurable):' | |||
|
312 | 313 | return printer(obj) |
|
313 | 314 | # Finally look for special method names |
|
314 | 315 | method = pretty._safe_getattr(obj, self.print_method, None) |
|
315 | if method is not None: | |
|
316 | # print_method must be a bound method: | |
|
317 | if isinstance(method, types.MethodType) and method.__self__ is not None: | |
|
316 | 318 | return method() |
|
317 | 319 | return None |
|
318 | 320 | else: |
@@ -8,6 +8,7 b' except:' | |||
|
8 | 8 | numpy = None |
|
9 | 9 | import nose.tools as nt |
|
10 | 10 | |
|
11 | from IPython.config import Config | |
|
11 | 12 | from IPython.core.formatters import ( |
|
12 | 13 | PlainTextFormatter, HTMLFormatter, PDFFormatter, _mod_name_key |
|
13 | 14 | ) |
@@ -289,3 +290,33 b' def test_pdf_formatter():' | |||
|
289 | 290 | pdf = MakePDF() |
|
290 | 291 | f = PDFFormatter() |
|
291 | 292 | nt.assert_equal(f(pdf), 'PDF') |
|
293 | ||
|
294 | def test_print_method_bound(): | |
|
295 | f = HTMLFormatter() | |
|
296 | class MyHTML(object): | |
|
297 | def _repr_html_(self): | |
|
298 | return "hello" | |
|
299 | ||
|
300 | with capture_output() as captured: | |
|
301 | result = f(MyHTML) | |
|
302 | nt.assert_is(result, None) | |
|
303 | nt.assert_not_in("FormatterWarning", captured.stderr) | |
|
304 | ||
|
305 | with capture_output() as captured: | |
|
306 | result = f(MyHTML()) | |
|
307 | nt.assert_equal(result, "hello") | |
|
308 | nt.assert_equal(captured.stderr, "") | |
|
309 | ||
|
310 | def test_format_config(): | |
|
311 | """config objects don't pretend to support fancy reprs with lazy attrs""" | |
|
312 | f = HTMLFormatter() | |
|
313 | cfg = Config() | |
|
314 | with capture_output() as captured: | |
|
315 | result = f(cfg) | |
|
316 | nt.assert_is(result, None) | |
|
317 | nt.assert_equal(captured.stderr, "") | |
|
318 | ||
|
319 | with capture_output() as captured: | |
|
320 | result = f(Config) | |
|
321 | nt.assert_is(result, None) | |
|
322 | nt.assert_equal(captured.stderr, "") |
General Comments 0
You need to be logged in to leave comments.
Login now