From 2cadcca9043e6ae3ddf0b4cb9ddd9caa0c668f1e Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Mon, 10 Jul 2023 14:29:31 +0200 Subject: [PATCH] #1248: Reuse Docker images in functional tests --- .github/workflows/test.yml | 5 ++++- tests/Dockerfile | 7 +++++++ tests/functional/conftest.py | 6 ++++++ tests/functional/test_bash.py | 10 ++++------ tests/functional/test_fish.py | 20 ++------------------ tests/functional/test_tcsh.py | 14 ++------------ tests/functional/test_zsh.py | 15 ++------------- 7 files changed, 27 insertions(+), 50 deletions(-) create mode 100644 tests/Dockerfile create mode 100644 tests/functional/conftest.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51c91c35..2fa403a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,7 +41,10 @@ jobs: run: coverage run --source=thefuck,tests -m pytest -v --capture=sys tests - name: Run tests (including functional) 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 if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_LATEST env: diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 00000000..62634af0 --- /dev/null +++ b/tests/Dockerfile @@ -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 diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py new file mode 100644 index 00000000..2ff5fddf --- /dev/null +++ b/tests/functional/conftest.py @@ -0,0 +1,6 @@ +import pytest + + +@pytest.fixture(autouse=True) +def build_container_mock(mocker): + return mocker.patch('pytest_docker_pexpect.docker.build_container') diff --git a/tests/functional/test_bash.py b/tests/functional/test_bash.py index dbb6fed2..7fb988ed 100644 --- a/tests/functional/test_bash.py +++ b/tests/functional/test_bash.py @@ -4,12 +4,12 @@ from tests.functional.plots import with_confirmation, without_confirmation, \ select_command_with_arrows, how_to_configure -python_3 = (u'thefuck/python3-bash', - u'FROM python:3', +python_3 = (u'thefuck/python3', + u'', u'sh') -python_2 = (u'thefuck/python2-bash', - u'FROM python:2', +python_2 = (u'thefuck/python2', + u'', u'sh') @@ -28,8 +28,6 @@ echo "instant mode ready: $THEFUCK_INSTANT_MODE" def proc(request, spawnu, TIMEOUT): container, instant_mode = request.param proc = spawnu(*container) - proc.sendline(u"pip install /src") - assert proc.expect([TIMEOUT, u'Successfully installed']) proc.sendline(init_bashrc.format( u'--enable-experimental-instant-mode' if instant_mode else '')) proc.sendline(u"bash") diff --git a/tests/functional/test_fish.py b/tests/functional/test_fish.py index 657ebf19..cbf04f27 100644 --- a/tests/functional/test_fish.py +++ b/tests/functional/test_fish.py @@ -2,29 +2,13 @@ import pytest from tests.functional.plots import with_confirmation, without_confirmation, \ refuse_with_confirmation, select_command_with_arrows -containers = (('thefuck/python3-fish', - u'''FROM python:3 - # 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')) +containers = ((u'thefuck/python3', u'', u'fish'), + (u'thefuck/python2', u'', u'fish')) @pytest.fixture(params=containers) def proc(request, spawnu, TIMEOUT): 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'fish') return proc diff --git a/tests/functional/test_tcsh.py b/tests/functional/test_tcsh.py index 12cabe30..06dcad0e 100644 --- a/tests/functional/test_tcsh.py +++ b/tests/functional/test_tcsh.py @@ -2,23 +2,13 @@ import pytest from tests.functional.plots import with_confirmation, without_confirmation, \ refuse_with_confirmation, select_command_with_arrows -containers = (('thefuck/python3-tcsh', - u'''FROM python:3 - 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')) +containers = ((u'thefuck/python3', u'', u'tcsh'), + (u'thefuck/python2', u'', u'tcsh')) @pytest.fixture(params=containers) def proc(request, spawnu, TIMEOUT): proc = spawnu(*request.param) - proc.sendline(u'pip install /src') - assert proc.expect([TIMEOUT, u'Successfully installed']) proc.sendline(u'tcsh') proc.sendline(u'setenv PYTHONIOENCODING utf8') proc.sendline(u'eval `thefuck --alias`') diff --git a/tests/functional/test_zsh.py b/tests/functional/test_zsh.py index f8ea2af5..f267e243 100644 --- a/tests/functional/test_zsh.py +++ b/tests/functional/test_zsh.py @@ -4,17 +4,8 @@ from tests.functional.plots import with_confirmation, without_confirmation, \ select_command_with_arrows, how_to_configure -python_3 = ('thefuck/python3-zsh', - u'''FROM python:3 - 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') +python_3 = (u'thefuck/python3', u'', u'sh') +python_2 = (u'thefuck/python2', u'', u'sh') init_zshrc = u'''echo ' @@ -35,8 +26,6 @@ echo "instant mode ready: $THEFUCK_INSTANT_MODE" def proc(request, spawnu, TIMEOUT): container, instant_mode = request.param proc = spawnu(*container) - proc.sendline(u'pip install /src') - assert proc.expect([TIMEOUT, u'Successfully installed']) proc.sendline(init_zshrc.format( u'--enable-experimental-instant-mode' if instant_mode else '')) proc.sendline(u"zsh")