Show More
@@ -8,6 +8,7 b' import bdb' | |||
|
8 | 8 | import builtins |
|
9 | 9 | import os |
|
10 | 10 | import sys |
|
11 | import platform | |
|
11 | 12 | |
|
12 | 13 | from tempfile import NamedTemporaryFile |
|
13 | 14 | from textwrap import dedent |
@@ -16,6 +17,7 b' from unittest.mock import patch' | |||
|
16 | 17 | from IPython.core import debugger |
|
17 | 18 | from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE |
|
18 | 19 | from IPython.testing.decorators import skip_win32 |
|
20 | import pytest | |
|
19 | 21 | |
|
20 | 22 | #----------------------------------------------------------------------------- |
|
21 | 23 | # Helper classes, from CPython's Pdb test suite |
@@ -411,6 +413,7 b' def test_decorator_skip():' | |||
|
411 | 413 | child.close() |
|
412 | 414 | |
|
413 | 415 | |
|
416 | @pytest.mark.skip(platform.python_implementation() == "PyPy", reason="issues on PyPy") | |
|
414 | 417 | @skip_win32 |
|
415 | 418 | def test_decorator_skip_disabled(): |
|
416 | 419 | """test that decorator frame skipping can be disabled""" |
@@ -438,6 +441,7 b' def test_decorator_skip_disabled():' | |||
|
438 | 441 | child.close() |
|
439 | 442 | |
|
440 | 443 | |
|
444 | @pytest.mark.skip(platform.python_implementation() == "PyPy", reason="issues on PyPy") | |
|
441 | 445 | @skip_win32 |
|
442 | 446 | def test_decorator_skip_with_breakpoint(): |
|
443 | 447 | """test that decorator frame skipping can be disabled""" |
@@ -102,10 +102,16 b' else:' | |||
|
102 | 102 | _use_simple_prompt = ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or (not _is_tty) |
|
103 | 103 | |
|
104 | 104 | def black_reformat_handler(text_before_cursor): |
|
105 | """ | |
|
106 | We do not need to protect against error, | |
|
107 | this is taken care at a higher level where any reformat error is ignored. | |
|
108 | Indeed we may call reformatting on incomplete code. | |
|
109 | """ | |
|
105 | 110 | import black |
|
111 | ||
|
106 | 112 | formatted_text = black.format_str(text_before_cursor, mode=black.FileMode()) |
|
107 |
if not text_before_cursor.endswith( |
|
|
108 | formatted_text = formatted_text[:-1] | |
|
113 | if not text_before_cursor.endswith("\n") and formatted_text.endswith("\n"): | |
|
114 | formatted_text = formatted_text[:-1] | |
|
109 | 115 | return formatted_text |
|
110 | 116 | |
|
111 | 117 | |
@@ -176,7 +182,8 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
176 | 182 | sequence to complete.""", |
|
177 | 183 | ).tag(config=True) |
|
178 | 184 | |
|
179 |
autoformatter = Unicode( |
|
|
185 | autoformatter = Unicode( | |
|
186 | "black", | |
|
180 | 187 | help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`", |
|
181 | 188 | allow_none=True |
|
182 | 189 | ).tag(config=True) |
@@ -210,9 +217,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
210 | 217 | if self.pt_app: |
|
211 | 218 | self.pt_app.editing_mode = getattr(EditingMode, change.new.upper()) |
|
212 | 219 | |
|
213 | @observe('autoformatter') | |
|
214 | def _autoformatter_changed(self, change): | |
|
215 | formatter = change.new | |
|
220 | def _set_formatter(self, formatter): | |
|
216 | 221 | if formatter is None: |
|
217 | 222 | self.reformat_handler = lambda x:x |
|
218 | 223 | elif formatter == 'black': |
@@ -220,6 +225,11 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
220 | 225 | else: |
|
221 | 226 | raise ValueError |
|
222 | 227 | |
|
228 | @observe("autoformatter") | |
|
229 | def _autoformatter_changed(self, change): | |
|
230 | formatter = change.new | |
|
231 | self._set_formatter(formatter) | |
|
232 | ||
|
223 | 233 | @observe('highlighting_style') |
|
224 | 234 | @observe('colors') |
|
225 | 235 | def _highlighting_style_changed(self, change): |
@@ -561,6 +571,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
561 | 571 | self.init_prompt_toolkit_cli() |
|
562 | 572 | self.init_term_title() |
|
563 | 573 | self.keep_running = True |
|
574 | self._set_formatter(self.autoformatter) | |
|
564 | 575 | |
|
565 | 576 | |
|
566 | 577 | def ask_exit(self): |
General Comments 0
You need to be logged in to leave comments.
Login now