##// END OF EJS Templates
Merge pull request #10274 from ipython/auto-backport-of-pr-10249...
Matthias Bussonnier -
r23345:294a52c0 merge
parent child Browse files
Show More
@@ -407,6 +407,9 b' def test_ipython_display_formatter():'
407 def _ipython_display_(self):
407 def _ipython_display_(self):
408 raise NotImplementedError
408 raise NotImplementedError
409
409
410 save_enabled = f.ipython_display_formatter.enabled
411 f.ipython_display_formatter.enabled = True
412
410 yes = SelfDisplaying()
413 yes = SelfDisplaying()
411 no = NotSelfDisplaying()
414 no = NotSelfDisplaying()
412
415
@@ -420,6 +423,9 b' def test_ipython_display_formatter():'
420 nt.assert_equal(md, {})
423 nt.assert_equal(md, {})
421 nt.assert_equal(catcher, [yes])
424 nt.assert_equal(catcher, [yes])
422
425
426 f.ipython_display_formatter.enabled = save_enabled
427
428
423 def test_json_as_string_deprecated():
429 def test_json_as_string_deprecated():
424 class JSONString(object):
430 class JSONString(object):
425 def _repr_json_(self):
431 def _repr_json_(self):
@@ -207,6 +207,8 b' class TerminalInteractiveShell(InteractiveShell):'
207 super(TerminalInteractiveShell, self).init_display_formatter()
207 super(TerminalInteractiveShell, self).init_display_formatter()
208 # terminal only supports plain text
208 # terminal only supports plain text
209 self.display_formatter.active_types = ['text/plain']
209 self.display_formatter.active_types = ['text/plain']
210 # disable `_ipython_display_`
211 self.display_formatter.ipython_display_formatter.enabled = False
210
212
211 def init_prompt_toolkit_cli(self):
213 def init_prompt_toolkit_cli(self):
212 if self.simple_prompt:
214 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