Show More
@@ -274,8 +274,6 class TerminalInteractiveShell(InteractiveShell): | |||||
274 | super(TerminalInteractiveShell, self).init_display_formatter() |
|
274 | super(TerminalInteractiveShell, self).init_display_formatter() | |
275 | # terminal only supports plain text |
|
275 | # terminal only supports plain text | |
276 | self.display_formatter.active_types = ['text/plain'] |
|
276 | self.display_formatter.active_types = ['text/plain'] | |
277 | # disable `_ipython_display_` |
|
|||
278 | self.display_formatter.ipython_display_formatter.enabled = False |
|
|||
279 |
|
277 | |||
280 | def init_prompt_toolkit_cli(self): |
|
278 | def init_prompt_toolkit_cli(self): | |
281 | if self.simple_prompt: |
|
279 | if self.simple_prompt: |
@@ -135,11 +135,14 class InteractiveShellTestCase(unittest.TestCase): | |||||
135 | finally: |
|
135 | finally: | |
136 | ip.input_transformers_post.remove(syntax_error_transformer) |
|
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 | ip = get_ipython() |
|
139 | ip = get_ipython() | |
140 | formatter = ip.display_formatter |
|
140 | formatter = ip.display_formatter | |
141 | assert formatter.active_types == ['text/plain'] |
|
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 | class Test(object): |
|
147 | class Test(object): | |
145 | def __repr__(self): |
|
148 | def __repr__(self): | |
@@ -155,16 +158,27 class InteractiveShellTestCase(unittest.TestCase): | |||||
155 |
|
158 | |||
156 | class Test2(Test): |
|
159 | class Test2(Test): | |
157 | def _ipython_display_(self): |
|
160 | def _ipython_display_(self): | |
158 | from IPython.display import display |
|
161 | from IPython.display import display, HTML | |
159 | display('<custom>') |
|
162 | display(HTML('<custom>')) | |
160 |
|
163 | |||
161 |
# verify that |
|
164 | # verify that mimehandlers are called | |
162 | obj = Test2() |
|
165 | called = False | |
163 | with capture_output() as captured: |
|
|||
164 | data, _ = formatter.format(obj) |
|
|||
165 |
|
166 | |||
166 | self.assertEqual(data, {'text/plain': repr(obj)}) |
|
167 | def handler(data, metadata): | |
167 | assert captured.stdout == '' |
|
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 | def syntax_error_transformer(lines): |
|
183 | def syntax_error_transformer(lines): | |
170 | """Transformer that throws SyntaxError if 'syntaxerror' is in the code.""" |
|
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