From 70c89164b0c148d87ade21d6a25090e203e84272 Mon Sep 17 00:00:00 2001 From: nvbn Date: Thu, 30 Jul 2015 18:28:20 +0300 Subject: [PATCH] #298 Add func tests for selecting rule --- .travis.yml | 1 + tests/functional/plots.py | 22 +++++++++++++++++++++- tests/functional/test_bash.py | 17 ++++++++++++----- tests/functional/test_fish.py | 13 ++++++++++--- tests/functional/test_tcsh.py | 13 ++++++++++--- tests/functional/test_zsh.py | 18 +++++++++++++----- thefuck/ui.py | 10 +++++----- 7 files changed, 72 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1fea4fc7..65dc39fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ addons: - fish - tcsh - pandoc + - git env: - FUNCTIONAL=true BARE=true install: diff --git a/tests/functional/plots.py b/tests/functional/plots.py index 46eaf005..611742f2 100644 --- a/tests/functional/plots.py +++ b/tests/functional/plots.py @@ -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) diff --git a/tests/functional/test_bash.py b/tests/functional/test_bash.py index a40361cd..d489708a 100644 --- a/tests/functional/test_bash.py +++ b/tests/functional/test_bash.py @@ -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') diff --git a/tests/functional/test_fish.py b/tests/functional/test_fish.py index d465faf3..5ff7f5c0 100644 --- a/tests/functional/test_fish.py +++ b/tests/functional/test_fish.py @@ -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') diff --git a/tests/functional/test_tcsh.py b/tests/functional/test_tcsh.py index 6dd926cc..75c3bb42 100644 --- a/tests/functional/test_tcsh.py +++ b/tests/functional/test_tcsh.py @@ -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) diff --git a/tests/functional/test_zsh.py b/tests/functional/test_zsh.py index 0201fa36..610cc23c 100644 --- a/tests/functional/test_zsh.py +++ b/tests/functional/test_zsh.py @@ -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') diff --git a/thefuck/ui.py b/thefuck/ui.py index 257b6e66..f0b49793 100644 --- a/thefuck/ui.py +++ b/thefuck/ui.py @@ -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()