From 51e34d2b8b84f1a582b4dbbfa3693957ddc3f48a Mon Sep 17 00:00:00 2001 From: Adam Hupp Date: Mon, 25 Apr 2022 15:21:35 -0700 Subject: use tox for all the multi-version testing --- .dockerignore | 1 + .gitignore | 2 +- __init__.py | 0 test/docker/alpine | 7 +++++-- test/docker/bionic | 11 ++++++----- test/docker/centos7 | 8 ++++++-- test/docker/centos8 | 8 +++++--- test/docker/focal | 11 ++++++----- test/docker/xenial | 11 ++++++----- test/run_all_versions.py | 35 ----------------------------------- tox.ini | 7 ++++--- 11 files changed, 40 insertions(+), 61 deletions(-) create mode 120000 .dockerignore delete mode 100644 __init__.py delete mode 100644 test/run_all_versions.py diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index 111565e..40c8c4e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ bin/ deb_dist htmlcov/ lib/ -__pycache__/ +**/__pycache__ python_magic.egg-info pip-selfcheck.json pyvenv.cfg diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/docker/alpine b/test/docker/alpine index eb511d7..c36b720 100755 --- a/test/docker/alpine +++ b/test/docker/alpine @@ -1,4 +1,7 @@ FROM python:3.8-alpine3.12 RUN apk add python3 python2 libmagic -COPY . /python-magic -CMD cd /python-magic/test && python3 ./run.py +WORKDIR /python-magic +COPY . . +RUN python3 -m pip install tox +CMD python3 -m tox + diff --git a/test/docker/bionic b/test/docker/bionic index e335b8e..2fe482c 100755 --- a/test/docker/bionic +++ b/test/docker/bionic @@ -1,8 +1,9 @@ FROM ubuntu:bionic +WORKDIR /python-magic +COPY . . RUN apt-get update -RUN apt-get -y install python -RUN apt-get -y install python3 -RUN apt-get -y install locales +RUN apt-get -y install python python3 locales python3-pip libmagic1 RUN locale-gen en_US.UTF-8 -COPY . /python-magic -CMD cd /python-magic/test && python3 ./run.py +RUN python3 -m pip install tox +CMD python3 -m tox + diff --git a/test/docker/centos7 b/test/docker/centos7 index f2ac6e4..10f170a 100644 --- a/test/docker/centos7 +++ b/test/docker/centos7 @@ -1,5 +1,9 @@ FROM centos:7 RUN yum -y update RUN yum -y install file-devel python3 python2 which -COPY . /python-magic -CMD cd /python-magic/test && SKIP_FROM_DESCRIPTOR=1 python3 ./run.py +WORKDIR /python-magic +COPY . . +RUN python3 -m pip install tox +ENV SKIP_FROM_DESCRIPTOR=1 +CMD python3 -m tox + diff --git a/test/docker/centos8 b/test/docker/centos8 index 968f6b6..3b3da0a 100644 --- a/test/docker/centos8 +++ b/test/docker/centos8 @@ -4,6 +4,8 @@ RUN yum -y install file-libs python3 python2 which glibc-locale-source RUN yum reinstall glibc-common -y && \ localedef -i en_US -f UTF-8 en_US.UTF-8 && \ echo "LANG=en_US.UTF-8" > /etc/locale.conf -ENV LANG en_US.UTF-8 -COPY . /python-magic -CMD cd /python-magic/test && python3 ./run.py +WORKDIR /python-magic +COPY . . +RUN python3 -m pip install tox +CMD python3 -m tox + diff --git a/test/docker/focal b/test/docker/focal index 74e4d78..b35040b 100755 --- a/test/docker/focal +++ b/test/docker/focal @@ -1,8 +1,9 @@ FROM ubuntu:focal +WORKDIR /python-magic +COPY . . RUN apt-get update -RUN apt-get -y install python2 -RUN apt-get -y install python3 -RUN apt-get -y install locales +RUN apt-get -y install python python3 locales python3-pip libmagic1 RUN locale-gen en_US.UTF-8 -COPY . /python-magic -CMD cd /python-magic/test && python3 ./run.py +RUN python3 -m pip install tox +CMD python3 -m tox + diff --git a/test/docker/xenial b/test/docker/xenial index bc0440b..e3c0433 100755 --- a/test/docker/xenial +++ b/test/docker/xenial @@ -1,8 +1,9 @@ FROM ubuntu:xenial +WORKDIR /python-magic +COPY . . RUN apt-get update -RUN apt-get -y install python -RUN apt-get -y install python3 -RUN apt-get -y install locales +RUN apt-get -y install python python3 locales python3-pip libmagic1 RUN locale-gen en_US.UTF-8 -COPY . /python-magic -CMD cd /python-magic/test && python3 ./run.py +RUN python3 -m pip install tox +CMD python3 -m tox + diff --git a/test/run_all_versions.py b/test/run_all_versions.py deleted file mode 100644 index d9e7ec5..0000000 --- a/test/run_all_versions.py +++ /dev/null @@ -1,35 +0,0 @@ -import subprocess -import os.path -import sys - -this_dir = os.path.dirname(sys.argv[0]) - -new_env = dict(os.environ) -new_env.update({ - 'LC_ALL': 'en_US.UTF-8', - 'PYTHONPATH': os.path.join(this_dir, ".."), -}) - - -def has_py(version): - ret = subprocess.run("which %s" % version, shell=True, stdout=subprocess.DEVNULL) - return ret.returncode == 0 - - -def run_test(versions): - found = False - for i in versions: - if not has_py(i): - # if this version doesn't exist in path, skip - continue - found = True - print("Testing %s" % i) - subprocess.run([i, os.path.join(this_dir, "python_magic_test.py")], env=new_env, check=True) - subprocess.run([i, os.path.join(this_dir, "libmagic_test.py")], env=new_env, check=True) - - if not found: - sys.exit("No versions found: " + str(versions)) - -run_test(["python2", "python2.7"]) -run_test(["python3.5", "python3.6", "python3.7", "python3.8", "python3.9"]) - diff --git a/tox.ini b/tox.ini index 6559598..1aa47a9 100644 --- a/tox.ini +++ b/tox.ini @@ -12,15 +12,15 @@ envlist = [testenv] commands = - coverage run --source=magic ./test/test.py + coverage run -m pytest setenv = COVERAGE_FILE=.coverage.{envname} LC_ALL=en_US.UTF-8 deps = .[test] - zope.testrunner coverage + pytest [testenv:coverage-clean] deps = coverage @@ -44,4 +44,5 @@ commands = deps = mypy skip_install = true commands = - mypy magic.pyi + mypy -p magic + -- cgit v1.2.1