mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
heal p2
This commit is contained in:
parent
bcf32b7a23
commit
427945d6d2
2 changed files with 35 additions and 16 deletions
13
news/health.rst
Normal file
13
news/health.rst
Normal file
|
@ -0,0 +1,13 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* pep8, lint and refator in pytest style ``test_ptk_multiline.py``
|
||||
|
||||
**Security:** None
|
|
@ -9,19 +9,20 @@ from prompt_toolkit.interface import CommandLineInterface
|
|||
from prompt_toolkit.document import Document
|
||||
from prompt_toolkit.buffer import Buffer, AcceptAction
|
||||
|
||||
from xonsh.environ import Env
|
||||
from xonsh.tools import ON_WINDOWS
|
||||
|
||||
from tools import DummyEnv
|
||||
|
||||
|
||||
Context = namedtuple('Context', ['indent', 'buffer', 'accept', 'cli', 'cr'])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ctx(xonsh_builtins):
|
||||
@pytest.fixture(scope='module')
|
||||
def ctx():
|
||||
"""Context in which the ptk multiline functionality will be tested."""
|
||||
builtins.__xonsh_env__ = DummyEnv()
|
||||
builtins.__xonsh_env__['INDENT'] = ' '
|
||||
from xonsh.ptk.key_bindings import carriage_return
|
||||
xonsh_builtins.__xonsh_env__ = Env()
|
||||
xonsh_builtins.__xonsh_env__['INDENT'] = ' '
|
||||
buffer = Buffer()
|
||||
buffer.accept_action = MagicMock(name='accept', spec=AcceptAction)
|
||||
cli = MagicMock(name='cli', spec=CommandLineInterface)
|
||||
|
@ -36,63 +37,68 @@ def test_colon_indent(ctx):
|
|||
document = Document('for i in range(5):')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.buffer.document.current_line == ctx.indent
|
||||
assert ctx.buffer.document.current_line == ctx.indent
|
||||
|
||||
|
||||
def test_dedent(ctx):
|
||||
document = Document('\n'+ctx.indent+'pass')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
|
||||
document = Document('\n'+2*ctx.indent+'continue')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.buffer.document.current_line == ctx.indent
|
||||
|
||||
|
||||
def test_nodedent(ctx):
|
||||
'''don't dedent if first line of ctx.buffer'''
|
||||
mock = MagicMock(return_value = True)
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch('xonsh.ptk.key_bindings.can_compile', mock):
|
||||
document = Document('pass')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.accept.mock_calls is not None
|
||||
|
||||
|
||||
mock = MagicMock(return_value = True)
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch('xonsh.ptk.key_bindings.can_compile', mock):
|
||||
document = Document(ctx.indent+'pass')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.accept.mock_calls is not None
|
||||
|
||||
|
||||
def test_continuation_line(ctx):
|
||||
document = Document('\nsecond line')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
|
||||
|
||||
def test_trailing_slash(ctx):
|
||||
mock = MagicMock(return_value = True)
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch('xonsh.ptk.key_bindings.can_compile', mock):
|
||||
document = Document('this line will \\')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
if not ON_WINDOWS:
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
else:
|
||||
assert ctx.accept.mock_calls is not None
|
||||
|
||||
|
||||
def test_cant_compile_newline(ctx):
|
||||
mock = MagicMock(return_value = False)
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch('xonsh.ptk.key_bindings.can_compile', mock):
|
||||
document = Document('for i in (1, 2, ')
|
||||
ctx.buffer.set_document(document)
|
||||
ctx.cr(ctx.buffer, ctx.cli)
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
assert ctx.buffer.document.current_line == ''
|
||||
|
||||
|
||||
def test_can_compile_and_executes(ctx):
|
||||
mock = MagicMock(return_value = True)
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch('xonsh.ptk.key_bindings.can_compile', mock):
|
||||
document = Document('ls')
|
||||
ctx.buffer.set_document(document)
|
||||
|
|
Loading…
Add table
Reference in a new issue