Show More
@@ -274,8 +274,6 class TerminalInteractiveShell(InteractiveShell): | |||
|
274 | 274 | super(TerminalInteractiveShell, self).init_display_formatter() |
|
275 | 275 | # terminal only supports plain text |
|
276 | 276 | self.display_formatter.active_types = ['text/plain'] |
|
277 | # disable `_ipython_display_` | |
|
278 | self.display_formatter.ipython_display_formatter.enabled = False | |
|
279 | 277 | |
|
280 | 278 | def init_prompt_toolkit_cli(self): |
|
281 | 279 | if self.simple_prompt: |
@@ -135,11 +135,14 class InteractiveShellTestCase(unittest.TestCase): | |||
|
135 | 135 | finally: |
|
136 | 136 | ip.input_transformers_post.remove(syntax_error_transformer) |
|
137 | 137 | |
|
138 |
def test_plain_text |
|
|
138 | def test_repl_not_plain_text(self): | |
|
139 | 139 | ip = get_ipython() |
|
140 | 140 | formatter = ip.display_formatter |
|
141 | 141 | assert formatter.active_types == ['text/plain'] |
|
142 | assert not formatter.ipython_display_formatter.enabled | |
|
142 | ||
|
143 | # terminal may have arbitrary mimetype handler to open external viewer | |
|
144 | # or inline images. | |
|
145 | assert formatter.ipython_display_formatter.enabled | |
|
143 | 146 | |
|
144 | 147 | class Test(object): |
|
145 | 148 | def __repr__(self): |
@@ -155,16 +158,27 class InteractiveShellTestCase(unittest.TestCase): | |||
|
155 | 158 | |
|
156 | 159 | class Test2(Test): |
|
157 | 160 | def _ipython_display_(self): |
|
158 | from IPython.display import display | |
|
159 | display('<custom>') | |
|
161 | from IPython.display import display, HTML | |
|
162 | display(HTML('<custom>')) | |
|
160 | 163 | |
|
161 |
# verify that |
|
|
162 | obj = Test2() | |
|
163 | with capture_output() as captured: | |
|
164 | data, _ = formatter.format(obj) | |
|
164 | # verify that mimehandlers are called | |
|
165 | called = False | |
|
165 | 166 | |
|
166 | self.assertEqual(data, {'text/plain': repr(obj)}) | |
|
167 | assert captured.stdout == '' | |
|
167 | def handler(data, metadata): | |
|
168 | print('Handler called') | |
|
169 | nonlocal called | |
|
170 | called = True | |
|
171 | ||
|
172 | ip.display_formatter.active_types.append("text/html") | |
|
173 | ip.display_formatter.formatters["text/html"].enabled = True | |
|
174 | ip.mime_renderers["text/html"] = handler | |
|
175 | ||
|
176 | ||
|
177 | obj = Test() | |
|
178 | display(obj) | |
|
179 | ||
|
180 | assert called == True | |
|
181 | ||
|
168 | 182 | |
|
169 | 183 | def syntax_error_transformer(lines): |
|
170 | 184 | """Transformer that throws SyntaxError if 'syntaxerror' is in the code.""" |
General Comments 0
You need to be logged in to leave comments.
Login now