From 92c9f62d4f8bbfb49d9291d4bee9e606bf286f5e Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 28 Aug 2021 17:06:56 +0200 Subject: [PATCH] chore: move tests from `tox` to `nox` --- .github/workflows/lint.yml | 8 +--- .github/workflows/test.yml | 8 +--- .travis.yml | 8 +--- noxfile.py | 75 ++++++++++++++++++++++++++++++++++++++ test-requirements.txt | 3 -- tests/install.sh | 9 ----- tests/travis.sh | 7 ---- tox.ini | 15 -------- 8 files changed, 79 insertions(+), 54 deletions(-) create mode 100644 noxfile.py delete mode 100755 tests/install.sh delete mode 100755 tests/travis.sh delete mode 100644 tox.ini diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 08a67c15..bcb50d2f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,11 +19,5 @@ jobs: python-version: 3.8 architecture: x64 - - name: Install/fetch dependencies - run: | - set -exuo pipefail - pip install --upgrade pip setuptools - pip install tox - - name: Run linter - run: tox -e lint + run: pipx run nox -s lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b86ecd4d..ea30cc0c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,11 +34,5 @@ jobs: python-version: ${{ matrix.python }} architecture: x64 - - name: Install/fetch dependencies - run: | - set -exuo pipefail - pip install --upgrade pip setuptools - ./tests/install.sh - - name: Run tests - run: ./tests/travis.sh + run: pipx run nox -s tests-${{ matrix.python }} diff --git a/.travis.yml b/.travis.yml index ff1e2ce0..79bfff2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,14 +20,10 @@ services: notifications: email: false -before_install: - - pip install --upgrade pip setuptools - install: - - ./tests/install.sh - + - pip install nox script: - - tests/travis.sh + - nox -s tests-3.8 cache: directories: diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..7c31de58 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,75 @@ +import os +import sys + +from pathlib import Path + +import nox + + +RUNNING_CI = "TRAVIS" in os.environ or "GITHUB_ACTIONS" in os.environ + + +@nox.session(reuse_venv=True) +def lint(session: nox.Session) -> str: + """ + Run linters on the codebase. + """ + session.install("flake8", "mypy") + session.run("flake8", "auditwheel") + session.run("mypy", "auditwheel") + + +@nox.session() +def coverage(session: nox.Session) -> str: + """ + Run coverage using unit tests. + """ + session.install("-r", "test-requirements.txt", "pytest-cov") + session.run( + "python", + "-m", + "pytest", + "tests/unit", + "--cov=auditwheel", + "--cov-report=term-missing" + ) + + +def _docker_images(session): + tmp_dir = Path(session.create_tmp()) + script = tmp_dir / "list_images.py" + images_file = tmp_dir / "images.lst" + script.write_text( + fr""" +from pathlib import Path +from tests.integration.test_manylinux import MANYLINUX_IMAGES +images = "\n".join(MANYLINUX_IMAGES.values()) +Path(r"{images_file}").write_text(images) +""" + ) + session.run("python", str(script), silent=True) + return images_file.read_text().splitlines() + + +@nox.session(python=["3.6", "3.7", "3.8", "3.9"]) +def tests(session: nox.Session) -> str: + """ + Run tests. + """ + posargs = session.posargs + session.install("-r", "test-requirements.txt", "-e", ".") + if RUNNING_CI: + session.install("pytest-cov", "codecov") + posargs.extend(["--cov", "auditwheel", "--cov-branch"]) + # pull manylinux images that will be used. + # this helps passing tests which would otherwise timeout. + for image in _docker_images(session): + session.run("docker", "pull", image, external=True) + + session.run("pytest", "-s", *posargs) + if RUNNING_CI: + session.run("auditwheel", "lddtree", sys.executable) + try: + session.run("codecov") + except nox.command.CommandFailed: + pass # Ignore failures from codecov tool diff --git a/test-requirements.txt b/test-requirements.txt index a42a3b01..588974f6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,9 +1,6 @@ pytest>=3.4 -pytest-cov jsonschema pypatchelf -flake8 pretend docker pyelftools -mypy diff --git a/tests/install.sh b/tests/install.sh deleted file mode 100755 index 6df48207..00000000 --- a/tests/install.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -set -exuo pipefail - -pip install -r test-requirements.txt -pip install tox codecov -pip install -e . -# pull manylinux images that will be used, this helps passing tests which would otherwise timeout. -python -c $'from tests.integration.test_manylinux import MANYLINUX_IMAGES\nfor image in MANYLINUX_IMAGES.values():\n print(image)' | xargs -L 1 docker pull diff --git a/tests/travis.sh b/tests/travis.sh deleted file mode 100755 index d1ce6852..00000000 --- a/tests/travis.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -exuo pipefail - -pytest -s --cov auditwheel --cov-branch -auditwheel lddtree $(python -c 'import sys; print(sys.executable)') -codecov || true # Ignore failures from codecov tool diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 43c5b6d4..00000000 --- a/tox.ini +++ /dev/null @@ -1,15 +0,0 @@ -[tox] -minversion = 1.6 -skipsdist = True -envlist = py36,py37,py38,py39,lint,cov - -[testenv] -deps = -r{toxinidir}/test-requirements.txt -commands = pytest --doctest-modules auditwheel tests [] - -[testenv:lint] -commands = flake8 auditwheel - mypy auditwheel - -[testenv:cov] -commands = python -m pytest tests/unit --cov=auditwheel --cov-report=term-missing