##// END OF EJS Templates
Merge pull request #10249 from minrk/plain-text-only-no-display...
Thomas Kluyver -
r23311:1f445015 merge
parent child Browse files
Show More
@@ -407,6 +407,9 b' def test_ipython_display_formatter():'
407 407 def _ipython_display_(self):
408 408 raise NotImplementedError
409 409
410 save_enabled = f.ipython_display_formatter.enabled
411 f.ipython_display_formatter.enabled = True
412
410 413 yes = SelfDisplaying()
411 414 no = NotSelfDisplaying()
412 415
@@ -420,6 +423,9 b' def test_ipython_display_formatter():'
420 423 nt.assert_equal(md, {})
421 424 nt.assert_equal(catcher, [yes])
422 425
426 f.ipython_display_formatter.enabled = save_enabled
427
428
423 429 def test_json_as_string_deprecated():
424 430 class JSONString(object):
425 431 def _repr_json_(self):
@@ -203,6 +203,8 b' class TerminalInteractiveShell(InteractiveShell):'
203 203 super(TerminalInteractiveShell, self).init_display_formatter()
204 204 # terminal only supports plain text
205 205 self.display_formatter.active_types = ['text/plain']
206 # disable `_ipython_display_`
207 self.display_formatter.ipython_display_formatter.enabled = False
206 208
207 209 def init_prompt_toolkit_cli(self):
208 210 if self.simple_prompt:
@@ -1,17 +1,14 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Tests for the TerminalInteractiveShell and related pieces."""
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2011 The IPython Development Team
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 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
9 5
10 6 import sys
11 7 import unittest
12 8
13 9 from IPython.core.inputtransformer import InputTransformer
14 10 from IPython.testing import tools as tt
11 from IPython.utils.capture import capture_output
15 12
16 13 # Decorator for interaction loop tests -----------------------------------------
17 14
@@ -99,6 +96,33 b' class InteractiveShellTestCase(unittest.TestCase):'
99 96 ip = get_ipython()
100 97 formatter = ip.display_formatter
101 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 128 class SyntaxErrorTransformer(InputTransformer):
General Comments 0
You need to be logged in to leave comments. Login now