From 6b34bde052be74334dad71963d92a1c49eecd168 Mon Sep 17 00:00:00 2001 From: Adam Hupp Date: Mon, 25 Apr 2022 06:47:40 -0700 Subject: improve test script name clarity; expand test docs; cleanup docker run script --- test/README | 12 ++++-------- test/run.py | 35 ----------------------------------- test/run_all_docker_test.sh | 13 +++++++++++++ test/run_all_versions.py | 35 +++++++++++++++++++++++++++++++++++ test_docker.sh | 18 ------------------ 5 files changed, 52 insertions(+), 61 deletions(-) delete mode 100644 test/run.py create mode 100755 test/run_all_docker_test.sh create mode 100644 test/run_all_versions.py delete mode 100755 test_docker.sh diff --git a/test/README b/test/README index 12d4e4f..c34cb6a 100644 --- a/test/README +++ b/test/README @@ -1,10 +1,6 @@ -To run the tests across a selection of Ubuntu LTS versions: +There are a few ways to run the python-magic tests -docker build -t "python_magic/xenial:latest" -f test/Dockerfile_xenial . -docker build -t "python_magic/bionic:latest" -f test/Dockerfile_bionic . -docker build -t "python_magic/focal:latest" -f test/Dockerfile_focal . - -docker run python_magic/xenial:latest -docker run python_magic/bionic:latest -docker run python_magic/focal:latest + 1. `pytest` will run the test suite against your default version of python + 2. `./test/run_all_versions.py` will run the tests against all installed versions of python. + 3. `./test/run_all_docker_test.sh` will run against a variety of different Linux distributions, using docker. diff --git a/test/run.py b/test/run.py deleted file mode 100644 index cf62eee..0000000 --- a/test/run.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, "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/test/run_all_docker_test.sh b/test/run_all_docker_test.sh new file mode 100755 index 0000000..68a2808 --- /dev/null +++ b/test/run_all_docker_test.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e +set -x + +ROOT=$(dirname $0)/.. +cd $ROOT + +for f in test/docker/*; do + H=$(docker build -q -f ${f} .) + docker run --rm $H +done + diff --git a/test/run_all_versions.py b/test/run_all_versions.py new file mode 100644 index 0000000..cf62eee --- /dev/null +++ b/test/run_all_versions.py @@ -0,0 +1,35 @@ +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, "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/test_docker.sh b/test_docker.sh deleted file mode 100755 index ad2bc5d..0000000 --- a/test_docker.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# Test with various versions of ubuntu. This more or less re-creates the -# Travis CI test environment - -set -e - -DEFAULT_TARGETS="xenial bionic focal centos7 centos8 archlinux alpine" - -TARGETS=${1:-${DEFAULT_TARGETS}} - -HERE=`dirname $0` - -for i in $TARGETS; do - TAG="python_magic/${i}:latest" - docker build -t $TAG -f ${HERE}/test/docker/$i . - docker run $TAG -done -- cgit v1.2.1