##// END OF EJS Templates
disable `_ipython_display_` in terminal IPython...
Min RK -
Show More
@@ -203,6 +203,8 b' class TerminalInteractiveShell(InteractiveShell):'
203 super(TerminalInteractiveShell, self).init_display_formatter()
203 super(TerminalInteractiveShell, self).init_display_formatter()
204 # terminal only supports plain text
204 # terminal only supports plain text
205 self.display_formatter.active_types = ['text/plain']
205 self.display_formatter.active_types = ['text/plain']
206 # disable `_ipython_display_`
207 self.display_formatter.ipython_display_formatter.enabled = False
206
208
207 def init_prompt_toolkit_cli(self):
209 def init_prompt_toolkit_cli(self):
208 if self.simple_prompt:
210 if self.simple_prompt:
@@ -1,17 +1,14 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tests for the TerminalInteractiveShell and related pieces."""
2 """Tests for the TerminalInteractiveShell and related pieces."""
3 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Copyright (C) 2011 The IPython Development Team
4 # Distributed under the terms of the Modified BSD License.
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
5
10 import sys
6 import sys
11 import unittest
7 import unittest
12
8
13 from IPython.core.inputtransformer import InputTransformer
9 from IPython.core.inputtransformer import InputTransformer
14 from IPython.testing import tools as tt
10 from IPython.testing import tools as tt
11 from IPython.utils.capture import capture_output
15
12
16 # Decorator for interaction loop tests -----------------------------------------
13 # Decorator for interaction loop tests -----------------------------------------
17
14
@@ -99,6 +96,33 b' class InteractiveShellTestCase(unittest.TestCase):'
99 ip = get_ipython()
96 ip = get_ipython()
100 formatter = ip.display_formatter
97 formatter = ip.display_formatter
101 assert formatter.active_types == ['text/plain']
98 assert formatter.active_types == ['text/plain']
99 assert not formatter.ipython_display_formatter.enabled
100
101 class Test(object):
102 def __repr__(self):
103 return "<Test %i>" % id(self)
104
105 def _repr_html_(self):
106 return '<html>'
107
108 # verify that HTML repr isn't computed
109 obj = Test()
110 data, _ = formatter.format(obj)
111 self.assertEqual(data, {'text/plain': repr(obj)})
112
113 class Test2(Test):
114 def _ipython_display_(self):
115 from IPython.display import display
116 display('<custom>')
117
118 # verify that _ipython_display_ shortcut isn't called
119 obj = Test2()
120 with capture_output() as captured:
121 data, _ = formatter.format(obj)
122
123 self.assertEqual(data, {'text/plain': repr(obj)})
124 assert captured.stdout == ''
125
102
126
103
127
104 class SyntaxErrorTransformer(InputTransformer):
128 class SyntaxErrorTransformer(InputTransformer):
General Comments 0
You need to be logged in to leave comments. Login now