1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

#298 Add func tests for selecting rule

This commit is contained in:
nvbn 2015-07-30 18:28:20 +03:00
parent 1a76bfd2a3
commit 70c89164b0
7 changed files with 72 additions and 22 deletions

View File

@ -13,6 +13,7 @@ addons:
- fish
- tcsh
- pandoc
- git
env:
- FUNCTIONAL=true BARE=true
install:

View File

@ -23,7 +23,7 @@ def with_confirmation(proc):
assert proc.expect([TIMEOUT, u'test'])
def history_changed(proc, to=u'echo test'):
def history_changed(proc, to):
"""Ensures that history changed."""
proc.send('\033[A')
assert proc.expect([TIMEOUT, to])
@ -35,6 +35,26 @@ def history_not_changed(proc):
assert proc.expect([TIMEOUT, u'fuck'])
def select_command_with_arrows(proc):
"""Ensures that command can be selected with arrow keys."""
_set_confirmation(proc, True)
proc.sendline(u'git h')
assert proc.expect([TIMEOUT, u"git: 'h' is not a git command."])
proc.sendline(u'fuck')
assert proc.expect([TIMEOUT, u'git show'])
proc.send('\033[B')
assert proc.expect([TIMEOUT, u'git push'])
proc.send('\033[B')
assert proc.expect([TIMEOUT, u'git help'])
proc.send('\033[A')
assert proc.expect([TIMEOUT, u'git push'])
proc.send('\n')
assert proc.expect([TIMEOUT, u'Not a git repository'])
def refuse_with_confirmation(proc):
"""Ensures that fix can be refused when confirmation enabled."""
_set_confirmation(proc, True)

View File

@ -1,19 +1,20 @@
import pytest
from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation, history_changed, history_not_changed
refuse_with_confirmation, history_changed, history_not_changed, \
select_command_with_arrows
from tests.functional.utils import spawn, functional, images
containers = images(('ubuntu-python3-bash', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python3 python3-pip python3-dev
RUN apt-get install -yy python3 python3-pip python3-dev git
RUN pip3 install -U setuptools
RUN ln -s /usr/bin/pip3 /usr/bin/pip
'''),
('ubuntu-python2-bash', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python python-pip python-dev
RUN apt-get install -yy python python-pip python-dev git
RUN pip2 install -U pip setuptools
'''))
@ -31,7 +32,13 @@ def proc(request):
@functional
def test_with_confirmation(proc):
with_confirmation(proc)
history_changed(proc)
history_changed(proc, u'echo test')
@functional
def test_select_command_with_arrows(proc):
select_command_with_arrows(proc)
history_changed(proc, u'git push')
@functional
@ -43,4 +50,4 @@ def test_refuse_with_confirmation(proc):
@functional
def test_without_confirmation(proc):
without_confirmation(proc)
history_changed(proc)
history_changed(proc, u'echo test')

View File

@ -1,20 +1,22 @@
import pytest
from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation
refuse_with_confirmation, select_command_with_arrows
from tests.functional.utils import spawn, functional, images, bare
containers = images(('ubuntu-python3-fish', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python3 python3-pip python3-dev fish
RUN apt-get install -yy python3 python3-pip python3-dev fish git
RUN pip3 install -U setuptools
RUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN apt-get install -yy fish
'''),
('ubuntu-python2-fish', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python python-pip python-dev fish
RUN apt-get install -yy python python-pip python-dev git
RUN pip2 install -U pip setuptools
RUN apt-get install -yy fish
'''))
@ -34,6 +36,11 @@ def test_with_confirmation(proc):
with_confirmation(proc)
@functional
def test_select_command_with_arrows(proc):
select_command_with_arrows(proc)
@functional
@pytest.mark.skipif(
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')

View File

@ -1,20 +1,22 @@
import pytest
from tests.functional.utils import spawn, functional, images
from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation
refuse_with_confirmation, select_command_with_arrows
containers = images(('ubuntu-python3-tcsh', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python3 python3-pip python3-dev tcsh
RUN apt-get install -yy python3 python3-pip python3-dev git
RUN pip3 install -U setuptools
RUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN apt-get install -yy tcsh
'''),
('ubuntu-python2-tcsh', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python python-pip python-dev tcsh
RUN apt-get install -yy python python-pip python-dev git
RUN pip2 install -U pip setuptools
RUN apt-get install -yy tcsh
'''))
@ -32,6 +34,11 @@ def test_with_confirmation(proc):
with_confirmation(proc)
@functional
def test_select_command_with_arrows(proc):
select_command_with_arrows(proc)
@functional
def test_refuse_with_confirmation(proc):
refuse_with_confirmation(proc)

View File

@ -1,20 +1,22 @@
import pytest
from tests.functional.utils import spawn, functional, images
from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation, history_changed, history_not_changed
refuse_with_confirmation, history_changed, history_not_changed, select_command_with_arrows
containers = images(('ubuntu-python3-zsh', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python3 python3-pip python3-dev zsh
RUN apt-get install -yy python3 python3-pip python3-dev git
RUN pip3 install -U setuptools
RUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN apt-get install -yy zsh
'''),
('ubuntu-python2-zsh', u'''
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -yy python python-pip python-dev zsh
RUN apt-get install -yy python python-pip python-dev git
RUN pip2 install -U pip setuptools
RUN apt-get install -yy zsh
'''))
@ -31,7 +33,13 @@ def proc(request):
@functional
def test_with_confirmation(proc):
with_confirmation(proc)
history_changed(proc)
history_changed(proc, u'echo test')
@functional
def test_select_command_with_arrows(proc):
select_command_with_arrows(proc)
history_changed(proc, u'git push')
@functional
@ -43,4 +51,4 @@ def test_refuse_with_confirmation(proc):
@functional
def test_without_confirmation(proc):
without_confirmation(proc)
history_changed(proc)
history_changed(proc, u'echo test')

View File

@ -90,14 +90,14 @@ def select_command(corrected_commands, settings):
return selector.value
selector.on_change(lambda val: logs.confirm_text(val, settings))
for key in read_actions():
if key == SELECT:
for action in read_actions():
if action == SELECT:
sys.stderr.write('\n')
return selector.value
elif key == ABORT:
elif action == ABORT:
logs.failed('\nAborted', settings)
return
elif key == PREVIOUS:
elif action == PREVIOUS:
selector.previous()
elif key == NEXT:
elif action == NEXT:
selector.next()