diff --git a/IPython/core/tests/test_formatters.py b/IPython/core/tests/test_formatters.py index ab63ba4..2a07e2b 100644 --- a/IPython/core/tests/test_formatters.py +++ b/IPython/core/tests/test_formatters.py @@ -407,6 +407,9 @@ def test_ipython_display_formatter(): def _ipython_display_(self): raise NotImplementedError + save_enabled = f.ipython_display_formatter.enabled + f.ipython_display_formatter.enabled = True + yes = SelfDisplaying() no = NotSelfDisplaying() @@ -420,6 +423,9 @@ def test_ipython_display_formatter(): nt.assert_equal(md, {}) nt.assert_equal(catcher, [yes]) + f.ipython_display_formatter.enabled = save_enabled + + def test_json_as_string_deprecated(): class JSONString(object): def _repr_json_(self): diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 2aabab0..96f33cb 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -203,6 +203,8 @@ class TerminalInteractiveShell(InteractiveShell): super(TerminalInteractiveShell, self).init_display_formatter() # terminal only supports plain text self.display_formatter.active_types = ['text/plain'] + # disable `_ipython_display_` + self.display_formatter.ipython_display_formatter.enabled = False def init_prompt_toolkit_cli(self): if self.simple_prompt: diff --git a/IPython/terminal/tests/test_interactivshell.py b/IPython/terminal/tests/test_interactivshell.py index 9e76d5f..bc34a44 100644 --- a/IPython/terminal/tests/test_interactivshell.py +++ b/IPython/terminal/tests/test_interactivshell.py @@ -1,17 +1,14 @@ # -*- coding: utf-8 -*- """Tests for the TerminalInteractiveShell and related pieces.""" -#----------------------------------------------------------------------------- -# Copyright (C) 2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import sys import unittest from IPython.core.inputtransformer import InputTransformer from IPython.testing import tools as tt +from IPython.utils.capture import capture_output # Decorator for interaction loop tests ----------------------------------------- @@ -99,6 +96,33 @@ class InteractiveShellTestCase(unittest.TestCase): ip = get_ipython() formatter = ip.display_formatter assert formatter.active_types == ['text/plain'] + assert not formatter.ipython_display_formatter.enabled + + class Test(object): + def __repr__(self): + return "" % id(self) + + def _repr_html_(self): + return '' + + # verify that HTML repr isn't computed + obj = Test() + data, _ = formatter.format(obj) + self.assertEqual(data, {'text/plain': repr(obj)}) + + class Test2(Test): + def _ipython_display_(self): + from IPython.display import display + display('') + + # verify that _ipython_display_ shortcut isn't called + obj = Test2() + with capture_output() as captured: + data, _ = formatter.format(obj) + + self.assertEqual(data, {'text/plain': repr(obj)}) + assert captured.stdout == '' + class SyntaxErrorTransformer(InputTransformer):