mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
#N/A Simplify functional tests
This commit is contained in:
parent
7906025cc6
commit
c34a56bc89
@ -1,6 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from tests.functional.utils import build_container, spawn, run, read_until, \
|
from tests.functional.utils import spawn, functional
|
||||||
root, functional
|
|
||||||
|
|
||||||
containers = [('thefuck/ubuntu-python3-bash', '''
|
containers = [('thefuck/ubuntu-python3-bash', '''
|
||||||
FROM ubuntu:latest
|
FROM ubuntu:latest
|
||||||
@ -8,7 +7,6 @@ RUN apt-get update
|
|||||||
RUN apt-get install -yy python3 python3-pip python3-dev
|
RUN apt-get install -yy python3 python3-pip python3-dev
|
||||||
RUN pip3 install -U setuptools
|
RUN pip3 install -U setuptools
|
||||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
||||||
RUN echo "PS1='$ '" > /root/.bashrc
|
|
||||||
CMD ["/bin/bash"]
|
CMD ["/bin/bash"]
|
||||||
'''),
|
'''),
|
||||||
('thefuck/ubuntu-python2-bash', '''
|
('thefuck/ubuntu-python2-bash', '''
|
||||||
@ -16,7 +14,6 @@ FROM ubuntu:latest
|
|||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
RUN apt-get install -yy python python-pip python-dev
|
RUN apt-get install -yy python python-pip python-dev
|
||||||
RUN pip2 install -U pip setuptools
|
RUN pip2 install -U pip setuptools
|
||||||
RUN echo "PS1='$ '" > /root/.bashrc
|
|
||||||
CMD ["/bin/bash"]
|
CMD ["/bin/bash"]
|
||||||
''')]
|
''')]
|
||||||
|
|
||||||
@ -24,26 +21,31 @@ CMD ["/bin/bash"]
|
|||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
@pytest.mark.parametrize('tag, dockerfile', containers)
|
||||||
def test_with_confirmation(tag, dockerfile):
|
def test_with_confirmation(tag, dockerfile):
|
||||||
build_container(tag, dockerfile)
|
with spawn(tag, dockerfile) as proc:
|
||||||
with spawn(tag, '{}:/src'.format(root),
|
proc.sendline('eval $(thefuck-alias)')
|
||||||
['cd /src', 'pip install .', 'eval $(thefuck-alias)']) as proc:
|
|
||||||
run(proc, 'ehco test')
|
proc.sendline('ehco test')
|
||||||
|
proc.expect('command not found')
|
||||||
|
|
||||||
proc.sendline('fuck')
|
proc.sendline('fuck')
|
||||||
read_until(proc, '[')
|
proc.expect('echo test')
|
||||||
|
proc.expect('enter')
|
||||||
|
proc.expect_exact('ctrl+c')
|
||||||
proc.send('\n')
|
proc.send('\n')
|
||||||
out = read_until(proc)
|
|
||||||
assert out.split('\n')[-2] == 'test\r\r'
|
proc.expect('test')
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
@pytest.mark.parametrize('tag, dockerfile', containers)
|
||||||
def test_without_confirmation(tag, dockerfile):
|
def test_without_confirmation(tag, dockerfile):
|
||||||
build_container(tag, dockerfile)
|
with spawn(tag, dockerfile) as proc:
|
||||||
with spawn(tag, '{}:/src'.format(root),
|
proc.sendline('export THEFUCK_REQUIRE_CONFIRMATION=false')
|
||||||
['cd /src', 'pip install .',
|
proc.sendline('eval $(thefuck-alias)')
|
||||||
'export THEFUCK_REQUIRE_CONFIRMATION=false',
|
|
||||||
'eval $(thefuck-alias)']) as proc:
|
proc.sendline('ehco test')
|
||||||
run(proc, 'ehco test')
|
proc.expect('command not found')
|
||||||
run(proc, 'fuck')
|
|
||||||
out = read_until(proc)
|
proc.sendline('fuck')
|
||||||
assert out.split('\n')[-2] == 'test\r\r'
|
proc.expect('echo test')
|
||||||
|
proc.expect('test')
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from tests.functional.utils import build_container, spawn, run, read_until, \
|
from tests.functional.utils import spawn, functional
|
||||||
root, functional
|
|
||||||
|
|
||||||
containers = [('thefuck/ubuntu-python3-zsh', '''
|
containers = [('thefuck/ubuntu-python3-zsh', '''
|
||||||
FROM ubuntu:latest
|
FROM ubuntu:latest
|
||||||
@ -8,7 +7,6 @@ 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 zsh
|
||||||
RUN pip3 install -U setuptools
|
RUN pip3 install -U setuptools
|
||||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
||||||
RUN echo "PS1='\\n$ '" > /root/.zshrc
|
|
||||||
CMD ["/bin/zsh"]
|
CMD ["/bin/zsh"]
|
||||||
'''),
|
'''),
|
||||||
('thefuck/ubuntu-python2-zsh', '''
|
('thefuck/ubuntu-python2-zsh', '''
|
||||||
@ -16,7 +14,6 @@ FROM ubuntu:latest
|
|||||||
RUN apt-get update
|
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 zsh
|
||||||
RUN pip2 install -U pip setuptools
|
RUN pip2 install -U pip setuptools
|
||||||
RUN echo "PS1='\\n$ '" > /root/.zshrc
|
|
||||||
CMD ["/bin/zsh"]
|
CMD ["/bin/zsh"]
|
||||||
''')]
|
''')]
|
||||||
|
|
||||||
@ -24,27 +21,31 @@ CMD ["/bin/zsh"]
|
|||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
@pytest.mark.parametrize('tag, dockerfile', containers)
|
||||||
def test_with_confirmation(tag, dockerfile):
|
def test_with_confirmation(tag, dockerfile):
|
||||||
build_container(tag, dockerfile)
|
with spawn(tag, dockerfile) as proc:
|
||||||
with spawn(tag, '{}:/src'.format(root),
|
proc.sendline('eval $(thefuck-alias)')
|
||||||
['cd /src', 'pip install .', 'eval $(thefuck-alias)']) as proc:
|
|
||||||
run(proc, 'ehco "\ntest"')
|
proc.sendline('ehco test')
|
||||||
|
proc.expect('command not found')
|
||||||
|
|
||||||
proc.sendline('fuck')
|
proc.sendline('fuck')
|
||||||
read_until(proc, '[')
|
proc.expect('echo test')
|
||||||
|
proc.expect('enter')
|
||||||
|
proc.expect_exact('ctrl+c')
|
||||||
proc.send('\n')
|
proc.send('\n')
|
||||||
read_until(proc)
|
|
||||||
out = read_until(proc)
|
proc.expect('test')
|
||||||
assert out.split('\n')[-3] == 'test\r\r'
|
|
||||||
|
|
||||||
|
|
||||||
@functional
|
@functional
|
||||||
@pytest.mark.parametrize('tag, dockerfile', containers)
|
@pytest.mark.parametrize('tag, dockerfile', containers)
|
||||||
def test_without_confirmation(tag, dockerfile):
|
def test_without_confirmation(tag, dockerfile):
|
||||||
build_container(tag, dockerfile)
|
with spawn(tag, dockerfile) as proc:
|
||||||
with spawn(tag, '{}:/src'.format(root),
|
proc.sendline('export THEFUCK_REQUIRE_CONFIRMATION=false')
|
||||||
['cd /src', 'pip install .',
|
proc.sendline('eval $(thefuck-alias)')
|
||||||
'export THEFUCK_REQUIRE_CONFIRMATION=false',
|
|
||||||
'eval $(thefuck-alias)']) as proc:
|
proc.sendline('ehco test')
|
||||||
run(proc, 'ehco "\ntest"')
|
proc.expect('command not found')
|
||||||
run(proc, 'fuck')
|
|
||||||
out = read_until(proc)
|
proc.sendline('fuck')
|
||||||
assert out.split('\n')[-3] == 'test\r\r'
|
proc.expect('echo test')
|
||||||
|
proc.expect('test')
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
@ -15,38 +14,20 @@ def build_container(tag, dockerfile):
|
|||||||
tmpdir = mkdtemp()
|
tmpdir = mkdtemp()
|
||||||
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
|
with Path(tmpdir).joinpath('Dockerfile').open('w') as file:
|
||||||
file.write(dockerfile)
|
file.write(dockerfile)
|
||||||
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir]) != 0:
|
if subprocess.call(['docker', 'build', '--tag={}'.format(tag), tmpdir],
|
||||||
|
cwd=root) != 0:
|
||||||
raise Exception("Can't build container")
|
raise Exception("Can't build container")
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
def read_until(proc, string='\n$ '):
|
|
||||||
text = ''
|
|
||||||
while True:
|
|
||||||
text += proc.read(1)
|
|
||||||
sys.stdout.write(text[-1])
|
|
||||||
sys.stdout.flush()
|
|
||||||
if text.endswith(string):
|
|
||||||
return text
|
|
||||||
|
|
||||||
|
|
||||||
def run(proc, cmd):
|
|
||||||
proc.sendline(cmd)
|
|
||||||
return read_until(proc)
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def spawn(tag, volume, prepare=None):
|
def spawn(tag, dockerfile):
|
||||||
if prepare is None:
|
build_container(tag, dockerfile)
|
||||||
prepare = []
|
|
||||||
|
|
||||||
proc = pexpect.spawnu(
|
proc = pexpect.spawnu(
|
||||||
'docker run --volume {} --tty=true --interactive=true {}'.format(
|
'docker run --volume {}:/src --tty=true --interactive=true {}'.format(root, tag))
|
||||||
volume, tag))
|
proc.sendline('pip install /src')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for line in prepare:
|
|
||||||
run(proc, line)
|
|
||||||
yield proc
|
yield proc
|
||||||
finally:
|
finally:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user