From cd8fb9d25246d8bf90290356186056c631834b7a Mon Sep 17 00:00:00 2001 From: Adam Hupp Date: Tue, 5 May 2020 13:34:16 -0700 Subject: Improve test coverage Make sure we fail early if any versions fail, and move to a python test runner since I can never remember how to use bash. --- test/Dockerfile_bionic | 2 +- test/Dockerfile_focal | 2 +- test/Dockerfile_xenial | 2 +- test/run.py | 32 ++++++++++++++++++++++++++++++++ test/run.sh | 18 ------------------ 5 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 test/run.py delete mode 100755 test/run.sh (limited to 'test') diff --git a/test/Dockerfile_bionic b/test/Dockerfile_bionic index c180ea9..e335b8e 100755 --- a/test/Dockerfile_bionic +++ b/test/Dockerfile_bionic @@ -5,4 +5,4 @@ RUN apt-get -y install python3 RUN apt-get -y install locales RUN locale-gen en_US.UTF-8 COPY . /python-magic -CMD cd /python-magic/test && ./run.sh +CMD cd /python-magic/test && python3 ./run.py diff --git a/test/Dockerfile_focal b/test/Dockerfile_focal index 61f6745..74e4d78 100755 --- a/test/Dockerfile_focal +++ b/test/Dockerfile_focal @@ -5,4 +5,4 @@ RUN apt-get -y install python3 RUN apt-get -y install locales RUN locale-gen en_US.UTF-8 COPY . /python-magic -CMD cd /python-magic/test && ./run.sh +CMD cd /python-magic/test && python3 ./run.py diff --git a/test/Dockerfile_xenial b/test/Dockerfile_xenial index 1d43070..bc0440b 100755 --- a/test/Dockerfile_xenial +++ b/test/Dockerfile_xenial @@ -5,4 +5,4 @@ RUN apt-get -y install python3 RUN apt-get -y install locales RUN locale-gen en_US.UTF-8 COPY . /python-magic -CMD cd /python-magic/test && ./run.sh +CMD cd /python-magic/test && python3 ./run.py diff --git a/test/run.py b/test/run.py new file mode 100644 index 0000000..c10c11f --- /dev/null +++ b/test/run.py @@ -0,0 +1,32 @@ + +import subprocess +import os.path +import sys + +this_dir = os.path.dirname(sys.argv[0]) + +new_env = { + '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, "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"]) diff --git a/test/run.sh b/test/run.sh deleted file mode 100755 index 9676ee2..0000000 --- a/test/run.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - - -# ensure we can use unicode filenames in the test -export LC_ALL=en_US.UTF-8 -THISDIR=`dirname $0` -export PYTHONPATH=${THISDIR}/.. - -PYTHONS="python2.7 python3.5 python3.6 python3.7 python3.8 python" - -for pyver in $PYTHONS; do - if which $pyver > /dev/null; then - echo "found $pyver" - $pyver ${THISDIR}/test.py - else - echo "version $pyver not found" - fi -done -- cgit v1.2.1