summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdam Hupp <adam@hupp.org>2020-05-05 13:34:16 -0700
committerAdam Hupp <adam@hupp.org>2020-05-05 13:43:31 -0700
commitcd8fb9d25246d8bf90290356186056c631834b7a (patch)
treee6535061eb43ebf4ae42e4020ca9a32ac8d11ee3 /test
parent8ed5dc4759e7e7eb879494f246d3c5eec7580376 (diff)
downloadpython-magic-cd8fb9d25246d8bf90290356186056c631834b7a.tar.gz
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.
Diffstat (limited to 'test')
-rwxr-xr-xtest/Dockerfile_bionic2
-rwxr-xr-xtest/Dockerfile_focal2
-rwxr-xr-xtest/Dockerfile_xenial2
-rw-r--r--test/run.py32
-rwxr-xr-xtest/run.sh18
5 files changed, 35 insertions, 21 deletions
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