mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
#298 Simplify func tests
This commit is contained in:
parent
8962cf2ec1
commit
9d91b96780
@ -1,10 +1,16 @@
|
|||||||
from pexpect import TIMEOUT
|
from pexpect import TIMEOUT
|
||||||
|
|
||||||
|
|
||||||
|
def _set_confirmation(proc, require):
|
||||||
|
proc.sendline(u'mkdir -p ~/.thefuck')
|
||||||
|
proc.sendline(
|
||||||
|
u'echo "require_confirmation = {}" > ~/.thefuck/settings.py'.format(
|
||||||
|
require))
|
||||||
|
|
||||||
|
|
||||||
def with_confirmation(proc):
|
def with_confirmation(proc):
|
||||||
"""Ensures that command can be fixed when confirmation enabled."""
|
"""Ensures that command can be fixed when confirmation enabled."""
|
||||||
proc.sendline(u'mkdir -p ~/.thefuck')
|
_set_confirmation(proc, True)
|
||||||
proc.sendline(u'echo "require_confirmation = True" > ~/.thefuck/settings.py')
|
|
||||||
|
|
||||||
proc.sendline(u'ehco test')
|
proc.sendline(u'ehco test')
|
||||||
|
|
||||||
@ -17,10 +23,10 @@ def with_confirmation(proc):
|
|||||||
assert proc.expect([TIMEOUT, u'test'])
|
assert proc.expect([TIMEOUT, u'test'])
|
||||||
|
|
||||||
|
|
||||||
def history_changed(proc):
|
def history_changed(proc, to=u'echo test'):
|
||||||
"""Ensures that history changed."""
|
"""Ensures that history changed."""
|
||||||
proc.send('\033[A')
|
proc.send('\033[A')
|
||||||
assert proc.expect([TIMEOUT, u'echo test'])
|
assert proc.expect([TIMEOUT, to])
|
||||||
|
|
||||||
|
|
||||||
def history_not_changed(proc):
|
def history_not_changed(proc):
|
||||||
@ -31,8 +37,7 @@ def history_not_changed(proc):
|
|||||||
|
|
||||||
def refuse_with_confirmation(proc):
|
def refuse_with_confirmation(proc):
|
||||||
"""Ensures that fix can be refused when confirmation enabled."""
|
"""Ensures that fix can be refused when confirmation enabled."""
|
||||||
proc.sendline(u'mkdir -p ~/.thefuck')
|
_set_confirmation(proc, True)
|
||||||
proc.sendline(u'echo "require_confirmation = True" > ~/.thefuck/settings.py')
|
|
||||||
|
|
||||||
proc.sendline(u'ehco test')
|
proc.sendline(u'ehco test')
|
||||||
|
|
||||||
@ -47,8 +52,7 @@ def refuse_with_confirmation(proc):
|
|||||||
|
|
||||||
def without_confirmation(proc):
|
def without_confirmation(proc):
|
||||||
"""Ensures that command can be fixed when confirmation disabled."""
|
"""Ensures that command can be fixed when confirmation disabled."""
|
||||||
proc.sendline(u'mkdir -p ~/.thefuck')
|
_set_confirmation(proc, False)
|
||||||
proc.sendline(u'echo "require_confirmation = False" > ~/.thefuck/settings.py')
|
|
||||||
|
|
||||||
proc.sendline(u'ehco test')
|
proc.sendline(u'ehco test')
|
||||||
|
|
||||||
|
@ -18,34 +18,29 @@ RUN pip2 install -U pip setuptools
|
|||||||
'''))
|
'''))
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@pytest.fixture(params=containers)
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def proc(request):
|
||||||
def test_with_confirmation(tag, dockerfile):
|
tag, dockerfile = request.param
|
||||||
with spawn(tag, dockerfile, u'bash') as proc:
|
proc = spawn(request, tag, dockerfile, u'bash')
|
||||||
proc.sendline(u"export PS1='$ '")
|
proc.sendline(u"export PS1='$ '")
|
||||||
proc.sendline(u'eval $(thefuck-alias)')
|
proc.sendline(u'eval $(thefuck-alias)')
|
||||||
proc.sendline(u'touch $HISTFILE')
|
proc.sendline(u'touch $HISTFILE')
|
||||||
with_confirmation(proc)
|
return proc
|
||||||
history_changed(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_with_confirmation(proc):
|
||||||
def test_refuse_with_confirmation(tag, dockerfile):
|
with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'bash') as proc:
|
history_changed(proc)
|
||||||
proc.sendline(u"export PS1='$ '")
|
|
||||||
proc.sendline(u'eval $(thefuck-alias)')
|
|
||||||
proc.sendline(u'touch $HISTFILE')
|
|
||||||
refuse_with_confirmation(proc)
|
|
||||||
history_not_changed(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_refuse_with_confirmation(proc):
|
||||||
def test_without_confirmation(tag, dockerfile):
|
refuse_with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'bash') as proc:
|
history_not_changed(proc)
|
||||||
proc.sendline(u"export PS1='$ '")
|
|
||||||
proc.sendline(u'eval $(thefuck-alias)')
|
|
||||||
proc.sendline(u'touch $HISTFILE')
|
@functional
|
||||||
without_confirmation(proc)
|
def test_without_confirmation(proc):
|
||||||
history_changed(proc)
|
without_confirmation(proc)
|
||||||
|
history_changed(proc)
|
||||||
|
@ -18,36 +18,33 @@ RUN pip2 install -U pip setuptools
|
|||||||
'''))
|
'''))
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@pytest.fixture(params=containers)
|
||||||
@pytest.mark.skipif(
|
def proc(request):
|
||||||
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')
|
tag, dockerfile = request.param
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
proc = spawn(request, tag, dockerfile, u'fish')
|
||||||
def test_with_confirmation(tag, dockerfile):
|
proc.sendline(u'thefuck-alias > ~/.config/fish/config.fish')
|
||||||
with spawn(tag, dockerfile, u'fish') as proc:
|
proc.sendline(u'fish')
|
||||||
proc.sendline(u'thefuck-alias > ~/.config/fish/config.fish')
|
return proc
|
||||||
proc.sendline(u'fish')
|
|
||||||
with_confirmation(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')
|
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_with_confirmation(proc):
|
||||||
def test_refuse_with_confirmation(tag, dockerfile):
|
with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'fish') as proc:
|
|
||||||
proc.sendline(u'thefuck-alias > ~/.config/fish/config.fish')
|
|
||||||
proc.sendline(u'fish')
|
|
||||||
refuse_with_confirmation(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')
|
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_refuse_with_confirmation(proc):
|
||||||
def test_without_confirmation(tag, dockerfile):
|
refuse_with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'fish') as proc:
|
|
||||||
proc.sendline(u'thefuck-alias > ~/.config/fish/config.fish')
|
|
||||||
proc.sendline(u'fish')
|
@functional
|
||||||
without_confirmation(proc)
|
@pytest.mark.skipif(
|
||||||
|
bool(bare), reason='https://github.com/travis-ci/apt-source-whitelist/issues/71')
|
||||||
|
def test_without_confirmation(proc):
|
||||||
|
without_confirmation(proc)
|
||||||
|
|
||||||
# TODO: ensure that history changes.
|
# TODO: ensure that history changes.
|
||||||
|
@ -18,30 +18,27 @@ RUN pip2 install -U pip setuptools
|
|||||||
'''))
|
'''))
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@pytest.fixture(params=containers)
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def proc(request):
|
||||||
def test_with_confirmation(tag, dockerfile):
|
tag, dockerfile = request.param
|
||||||
with spawn(tag, dockerfile, u'tcsh') as proc:
|
proc = spawn(request, tag, dockerfile, u'tcsh')
|
||||||
proc.sendline(u'tcsh')
|
proc.sendline(u'tcsh')
|
||||||
proc.sendline(u'eval `thefuck-alias`')
|
proc.sendline(u'eval `thefuck-alias`')
|
||||||
with_confirmation(proc)
|
return proc
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_with_confirmation(proc):
|
||||||
def test_refuse_with_confirmation(tag, dockerfile):
|
with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'tcsh') as proc:
|
|
||||||
proc.sendline(u'tcsh')
|
|
||||||
proc.sendline(u'eval `thefuck-alias`')
|
|
||||||
refuse_with_confirmation(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_refuse_with_confirmation(proc):
|
||||||
def test_without_confirmation(tag, dockerfile):
|
refuse_with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'tcsh') as proc:
|
|
||||||
proc.sendline(u'tcsh')
|
|
||||||
proc.sendline(u'eval `thefuck-alias`')
|
@functional
|
||||||
without_confirmation(proc)
|
def test_without_confirmation(proc):
|
||||||
|
without_confirmation(proc)
|
||||||
|
|
||||||
# TODO: ensure that history changes.
|
# TODO: ensure that history changes.
|
||||||
|
@ -18,34 +18,29 @@ RUN pip2 install -U pip setuptools
|
|||||||
'''))
|
'''))
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@pytest.fixture(params=containers)
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def proc(request):
|
||||||
def test_with_confirmation(tag, dockerfile):
|
tag, dockerfile = request.param
|
||||||
with spawn(tag, dockerfile, u'zsh') as proc:
|
proc = spawn(request, tag, dockerfile, u'zsh')
|
||||||
proc.sendline(u'eval $(thefuck-alias)')
|
proc.sendline(u'eval $(thefuck-alias)')
|
||||||
proc.sendline(u'export HISTFILE=~/.zsh_history')
|
proc.sendline(u'export HISTFILE=~/.zsh_history')
|
||||||
proc.sendline(u'touch $HISTFILE')
|
proc.sendline(u'touch $HISTFILE')
|
||||||
with_confirmation(proc)
|
return proc
|
||||||
history_changed(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_with_confirmation(proc):
|
||||||
def test_refuse_with_confirmation(tag, dockerfile):
|
with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'zsh') as proc:
|
history_changed(proc)
|
||||||
proc.sendline(u'eval $(thefuck-alias)')
|
|
||||||
proc.sendline(u'export HISTFILE=~/.zsh_history')
|
|
||||||
proc.sendline(u'touch $HISTFILE')
|
|
||||||
refuse_with_confirmation(proc)
|
|
||||||
history_not_changed(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
def test_refuse_with_confirmation(proc):
|
||||||
def test_without_confirmation(tag, dockerfile):
|
refuse_with_confirmation(proc)
|
||||||
with spawn(tag, dockerfile, u'zsh') as proc:
|
history_not_changed(proc)
|
||||||
proc.sendline(u'eval $(thefuck-alias)')
|
|
||||||
proc.sendline(u'export HISTFILE=~/.zsh_history')
|
|
||||||
proc.sendline(u'touch $HISTFILE')
|
@functional
|
||||||
without_confirmation(proc)
|
def test_without_confirmation(proc):
|
||||||
history_changed(proc)
|
without_confirmation(proc)
|
||||||
|
history_changed(proc)
|
||||||
|
@ -23,8 +23,7 @@ def build_container(tag, dockerfile):
|
|||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
def spawn(request, tag, dockerfile, cmd):
|
||||||
def spawn(tag, dockerfile, cmd):
|
|
||||||
if bare:
|
if bare:
|
||||||
proc = pexpect.spawnu(cmd)
|
proc = pexpect.spawnu(cmd)
|
||||||
else:
|
else:
|
||||||
@ -36,10 +35,8 @@ def spawn(tag, dockerfile, cmd):
|
|||||||
|
|
||||||
proc.logfile = sys.stdout
|
proc.logfile = sys.stdout
|
||||||
|
|
||||||
try:
|
request.addfinalizer(proc.terminate)
|
||||||
yield proc
|
return proc
|
||||||
finally:
|
|
||||||
proc.terminate(force=bare)
|
|
||||||
|
|
||||||
|
|
||||||
def images(*items):
|
def images(*items):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user