1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 12:06:04 +00:00

#1248: Reuse Docker images in functional tests

This commit is contained in:
Pablo Santiago Blum de Aguiar 2023-07-10 14:29:31 +02:00
parent d81929f294
commit 2cadcca904
7 changed files with 27 additions and 50 deletions

View File

@ -41,7 +41,10 @@ jobs:
run: coverage run --source=thefuck,tests -m pytest -v --capture=sys tests run: coverage run --source=thefuck,tests -m pytest -v --capture=sys tests
- name: Run tests (including functional) - name: Run tests (including functional)
if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_LATEST if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_LATEST
run: coverage run --source=thefuck,tests -m pytest -v --capture=sys tests --enable-functional run: |
docker build -t thefuck/python3 -f tests/Dockerfile --build-arg PYTHON_VERSION=3 .
docker build -t thefuck/python2 -f tests/Dockerfile --build-arg PYTHON_VERSION=2 .
coverage run --source=thefuck,tests -m pytest -v --capture=sys tests --enable-functional
- name: Post coverage results - name: Post coverage results
if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_LATEST if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_LATEST
env: env:

7
tests/Dockerfile Normal file
View File

@ -0,0 +1,7 @@
ARG PYTHON_VERSION
FROM python:${PYTHON_VERSION}
RUN apt-get update -y
RUN apt-get install -yy --no-install-recommends --no-install-suggests fish tcsh zsh
RUN pip install --upgrade pip
COPY . /src
RUN pip install /src

View File

@ -0,0 +1,6 @@
import pytest
@pytest.fixture(autouse=True)
def build_container_mock(mocker):
return mocker.patch('pytest_docker_pexpect.docker.build_container')

View File

@ -4,12 +4,12 @@ from tests.functional.plots import with_confirmation, without_confirmation, \
select_command_with_arrows, how_to_configure select_command_with_arrows, how_to_configure
python_3 = (u'thefuck/python3-bash', python_3 = (u'thefuck/python3',
u'FROM python:3', u'',
u'sh') u'sh')
python_2 = (u'thefuck/python2-bash', python_2 = (u'thefuck/python2',
u'FROM python:2', u'',
u'sh') u'sh')
@ -28,8 +28,6 @@ echo "instant mode ready: $THEFUCK_INSTANT_MODE"
def proc(request, spawnu, TIMEOUT): def proc(request, spawnu, TIMEOUT):
container, instant_mode = request.param container, instant_mode = request.param
proc = spawnu(*container) proc = spawnu(*container)
proc.sendline(u"pip install /src")
assert proc.expect([TIMEOUT, u'Successfully installed'])
proc.sendline(init_bashrc.format( proc.sendline(init_bashrc.format(
u'--enable-experimental-instant-mode' if instant_mode else '')) u'--enable-experimental-instant-mode' if instant_mode else ''))
proc.sendline(u"bash") proc.sendline(u"bash")

View File

@ -2,29 +2,13 @@ import pytest
from tests.functional.plots import with_confirmation, without_confirmation, \ from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation, select_command_with_arrows refuse_with_confirmation, select_command_with_arrows
containers = (('thefuck/python3-fish', containers = ((u'thefuck/python3', u'', u'fish'),
u'''FROM python:3 (u'thefuck/python2', u'', u'fish'))
# Use jessie-backports since it has the fish package. See here for details:
# https://github.com/tianon/docker-brew-debian/blob/88ae21052affd8a14553bb969f9d41c464032122/jessie/backports/Dockerfile
RUN awk '$1 ~ "^deb" { $3 = $3 "-backports"; print; exit }' /etc/apt/sources.list > /etc/apt/sources.list.d/backports.list
RUN apt-get update
RUN apt-get install -yy fish''',
u'fish'),
('thefuck/python2-fish',
u'''FROM python:2
# Use jessie-backports since it has the fish package. See here for details:
# https://github.com/tianon/docker-brew-debian/blob/88ae21052affd8a14553bb969f9d41c464032122/jessie/backports/Dockerfile
RUN awk '$1 ~ "^deb" { $3 = $3 "-backports"; print; exit }' /etc/apt/sources.list > /etc/apt/sources.list.d/backports.list
RUN apt-get update
RUN apt-get install -yy fish''',
u'fish'))
@pytest.fixture(params=containers) @pytest.fixture(params=containers)
def proc(request, spawnu, TIMEOUT): def proc(request, spawnu, TIMEOUT):
proc = spawnu(*request.param) proc = spawnu(*request.param)
proc.sendline(u"pip install /src")
assert proc.expect([TIMEOUT, u'Successfully installed'])
proc.sendline(u'thefuck --alias > ~/.config/fish/config.fish') proc.sendline(u'thefuck --alias > ~/.config/fish/config.fish')
proc.sendline(u'fish') proc.sendline(u'fish')
return proc return proc

View File

@ -2,23 +2,13 @@ import pytest
from tests.functional.plots import with_confirmation, without_confirmation, \ from tests.functional.plots import with_confirmation, without_confirmation, \
refuse_with_confirmation, select_command_with_arrows refuse_with_confirmation, select_command_with_arrows
containers = (('thefuck/python3-tcsh', containers = ((u'thefuck/python3', u'', u'tcsh'),
u'''FROM python:3 (u'thefuck/python2', u'', u'tcsh'))
RUN apt-get update
RUN apt-get install -yy tcsh''',
u'tcsh'),
('thefuck/python2-tcsh',
u'''FROM python:2
RUN apt-get update
RUN apt-get install -yy tcsh''',
u'tcsh'))
@pytest.fixture(params=containers) @pytest.fixture(params=containers)
def proc(request, spawnu, TIMEOUT): def proc(request, spawnu, TIMEOUT):
proc = spawnu(*request.param) proc = spawnu(*request.param)
proc.sendline(u'pip install /src')
assert proc.expect([TIMEOUT, u'Successfully installed'])
proc.sendline(u'tcsh') proc.sendline(u'tcsh')
proc.sendline(u'setenv PYTHONIOENCODING utf8') proc.sendline(u'setenv PYTHONIOENCODING utf8')
proc.sendline(u'eval `thefuck --alias`') proc.sendline(u'eval `thefuck --alias`')

View File

@ -4,17 +4,8 @@ from tests.functional.plots import with_confirmation, without_confirmation, \
select_command_with_arrows, how_to_configure select_command_with_arrows, how_to_configure
python_3 = ('thefuck/python3-zsh', python_3 = (u'thefuck/python3', u'', u'sh')
u'''FROM python:3 python_2 = (u'thefuck/python2', u'', u'sh')
RUN apt-get update
RUN apt-get install -yy zsh''',
u'sh')
python_2 = ('thefuck/python2-zsh',
u'''FROM python:2
RUN apt-get update
RUN apt-get install -yy zsh''',
u'sh')
init_zshrc = u'''echo ' init_zshrc = u'''echo '
@ -35,8 +26,6 @@ echo "instant mode ready: $THEFUCK_INSTANT_MODE"
def proc(request, spawnu, TIMEOUT): def proc(request, spawnu, TIMEOUT):
container, instant_mode = request.param container, instant_mode = request.param
proc = spawnu(*container) proc = spawnu(*container)
proc.sendline(u'pip install /src')
assert proc.expect([TIMEOUT, u'Successfully installed'])
proc.sendline(init_zshrc.format( proc.sendline(init_zshrc.format(
u'--enable-experimental-instant-mode' if instant_mode else '')) u'--enable-experimental-instant-mode' if instant_mode else ''))
proc.sendline(u"zsh") proc.sendline(u"zsh")