##// END OF EJS Templates
Make the formatting of a code block name extendable...
Make the formatting of a code block name extendable Currently the user display of a code block requires a tight coupling between the caching compiler and the ultratb file, i.e., ultratb needs to know internal private variables of the caching compiler. This change makes the user-visible display of the code block name the responsibility of the caching compiler. A nice result is that the caching compiler can be overridden to have custom terminology in different systems for code blocks executed.

File last commit:

r27713:517a92f8
r27875:1c3678bf
Show More
test_shortcuts.py
40 lines | 1.3 KiB | text/x-python | PythonLexer
import pytest
from IPython.terminal.shortcuts import _apply_autosuggest
from unittest.mock import Mock
def make_event(text, cursor, suggestion):
event = Mock()
event.current_buffer = Mock()
event.current_buffer.suggestion = Mock()
event.current_buffer.cursor_position = cursor
event.current_buffer.suggestion.text = suggestion
event.current_buffer.document = Mock()
event.current_buffer.document.get_end_of_line_position = Mock(return_value=0)
event.current_buffer.document.text = text
event.current_buffer.document.cursor_position = cursor
return event
@pytest.mark.parametrize(
"text, cursor, suggestion, called",
[
("123456", 6, "123456789", True),
("123456", 3, "123456789", False),
("123456 \n789", 6, "123456789", True),
],
)
def test_autosuggest_at_EOL(text, cursor, suggestion, called):
"""
test that autosuggest is only applied at end of line.
"""
event = make_event(text, cursor, suggestion)
event.current_buffer.insert_text = Mock()
_apply_autosuggest(event)
if called:
event.current_buffer.insert_text.assert_called()
else:
event.current_buffer.insert_text.assert_not_called()
# event.current_buffer.document.get_end_of_line_position.assert_called()