Show More
@@ -26,6 +26,7 b' Authors:' | |||||
26 | # Stdlib imports |
|
26 | # Stdlib imports | |
27 | import abc |
|
27 | import abc | |
28 | import sys |
|
28 | import sys | |
|
29 | import types | |||
29 | import warnings |
|
30 | import warnings | |
30 |
|
31 | |||
31 | from IPython.external.decorator import decorator |
|
32 | from IPython.external.decorator import decorator | |
@@ -312,7 +313,8 b' class BaseFormatter(Configurable):' | |||||
312 | return printer(obj) |
|
313 | return printer(obj) | |
313 | # Finally look for special method names |
|
314 | # Finally look for special method names | |
314 | method = pretty._safe_getattr(obj, self.print_method, None) |
|
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 | return method() |
|
318 | return method() | |
317 | return None |
|
319 | return None | |
318 | else: |
|
320 | else: |
@@ -8,6 +8,7 b' except:' | |||||
8 | numpy = None |
|
8 | numpy = None | |
9 | import nose.tools as nt |
|
9 | import nose.tools as nt | |
10 |
|
10 | |||
|
11 | from IPython.config import Config | |||
11 | from IPython.core.formatters import ( |
|
12 | from IPython.core.formatters import ( | |
12 | PlainTextFormatter, HTMLFormatter, PDFFormatter, _mod_name_key |
|
13 | PlainTextFormatter, HTMLFormatter, PDFFormatter, _mod_name_key | |
13 | ) |
|
14 | ) | |
@@ -289,3 +290,33 b' def test_pdf_formatter():' | |||||
289 | pdf = MakePDF() |
|
290 | pdf = MakePDF() | |
290 | f = PDFFormatter() |
|
291 | f = PDFFormatter() | |
291 | nt.assert_equal(f(pdf), 'PDF') |
|
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