Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
- remove assimp from tests
- create pdm 'test' group for packages used by tests
- fix "coverage run" tests failing because Python env missing
  • Loading branch information
vjf committed Oct 10, 2024
1 parent 048395b commit 1caedde
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.tox/
.pdm-python
test/badge/
183 changes: 163 additions & 20 deletions pdm.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ dependencies = [
]
requires-python = ">=3.9"

[project.optional-dependencies]
test = [
"coverage>=7.6.2",
"defusedxml>=0.7.1",
"genbadge>=1.1.1",
"pytest>=8.3.3",
"httpx>=0.27.2",
]
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
Expand Down
14 changes: 13 additions & 1 deletion scripts/webapi/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
from owslib.feature.wfs110 import WebFeatureService_1_1_0
from owslib.util import ServiceException
from diskcache import Cache, Timeout
import pyassimp

# If assimp (https://github.com/assimp/assimp) shared library is in the path, then multi format export will be supported
try:
import pyassimp
HAS_ASSIMP = True
except ImportError:
HAS_ASSIMP = False

from types import SimpleNamespace
import copyreg
from lxml import etree
Expand Down Expand Up @@ -702,6 +709,11 @@ def convert_gltf2xxx(model, filename, fmt):
:param fmt: string indicating what format to convert to, e.g. 'DXF'
:returns: a file response
'''
# Exit if assimp library not available
if not HAS_ASSIMP:
LOGGER.warning(f"Assimp package not available or shared library not in LD_LIBRARY_PATH. Cannot convert {filename} to {fmt} and export")
return make_str_reponse("Multi-format export not supported. Please contact website administrator.")

# Use model name and file name to get full GLTF file path
gltf_path = find_gltf(GEOMODELS_DIR, INPUT_DIR, model, filename)
if not gltf_path:
Expand Down
20 changes: 10 additions & 10 deletions test/regression/reg_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ for i in 'pl' 'ts' 'vs' 'gp' 'wl'; do
echo -n "$i File test: "

# Convert GOCAD to COLLADA
coverage run -a $CONV_SCRIPT -g -f $CWD/output "$CWD/input/${i}Test.$i" $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output "$CWD/input/${i}Test.$i" $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - conversion returned False" && exit 1

# Remove date stamps from file
Expand All @@ -79,7 +79,7 @@ done

# Test second type of well file
echo -n "wl Type 2 File test: "
coverage run -a $CONV_SCRIPT -g -f $CWD/output "$CWD/input/wl2Test.wl" $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output "$CWD/input/wl2Test.wl" $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - conversion returned False" && exit 1
egrep -v '(<created>|<modified>)' "$CWD/output/wl2Test.dae" > "$CWD/output/wl2Test2.dae"
[ $? -ne 0 ] && echo "FAILED" && exit 1
Expand All @@ -93,7 +93,7 @@ compare_and_print "$CWD/output/wl2Test2.dae" "$CWD/golden/wl2Test.dae"
##########################################################################################

echo -n "Convert objects nested within 2 levels of group files: "
coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/2layer.gp $MODEL_INDIR/TasConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/2layer.gp $MODEL_INDIR/TasConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - 2 layer gp conversion returned False" && exit 1

# Remove date stamps from file
Expand All @@ -109,7 +109,7 @@ compare_and_print "$CWD/output/2layer2.dae" "$CWD/golden/2layer.dae"
##########################################################################################

echo -n "Inherit colour from group file: "
coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/gpColour.gp $MODEL_INDIR/TasConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/gpColour.gp $MODEL_INDIR/TasConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - inherit colour from gp returned False" && exit 1

# Remove date stamps from file
Expand All @@ -127,7 +127,7 @@ compare_and_print "$CWD/output/gpColour.dae" "$CWD/golden/gpColour.dae"
echo -n "Convert single layer VOXET to PNG test, with colour table: "

# Convert GOCAD to PNG with colour table
coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/PNGTest.vo $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/PNGTest.vo $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - ct conversion returned False" && exit 1

# Check that conversion was correct
Expand All @@ -137,7 +137,7 @@ compare_and_print "$CWD/output/PNGTest@@.PNG" "$CWD/golden/PNGTest.PNG"
echo -n "Convert single layer VOXET to PNG test, without colour table: "

# Convert GOCAD to PNG without colour table
coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/PNGTestNoCT.vo $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/PNGTestNoCT.vo $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - ct conversion returned False" && exit 1

# Check that conversion was correct
Expand All @@ -151,7 +151,7 @@ compare_and_print "$CWD/output/PNGTestNoCT@@.PNG" "$CWD/golden/PNGTestNoCT.PNG"

echo -n "Convert single layer RGBA voxet to PNG test: "

coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/RGBA_voxet.vo $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output $CWD/input/RGBA_voxet.vo $MODEL_INDIR/NorthGawlerConvParam.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - ct conversion returned False" && exit 1

# Check that conversion was correct
Expand All @@ -164,7 +164,7 @@ compare_and_print "$CWD/output/RGBA_voxet@@.PNG" "$CWD/golden/RGBA_voxet.PNG"

echo -n "Voxet with 3 binary files conversion & output config test: "

coverage run -a $CONV_SCRIPT -g -f $CWD/output -o smallConf.json $CWD/input/small_voxet/small.vo $CWD/input/small_voxet/small.json >/dev/null 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -f $CWD/output -o smallConf.json $CWD/input/small_voxet/small.vo $CWD/input/small_voxet/small.json >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - conversion returned False" && exit 1

# Check that conversion was correct
Expand All @@ -189,7 +189,7 @@ compare_and_print "$CWD/output/smallConf.json" "$CWD/golden/smallConf.json"
echo -n "Directory recursion test: "

# Try converting all files at once
coverage run -a $CONV_SCRIPT -g -r -f $CWD/output $CWD/input $MODEL_INDIR/NorthGawlerConvParam.json
python3 -m coverage run -a $CONV_SCRIPT -g -r -f $CWD/output $CWD/input $MODEL_INDIR/NorthGawlerConvParam.json
# >/dev/null 2>&1
[ $? -ne 0 ] && echo "FAILED - conversion returned False" && exit 1

Expand All @@ -211,7 +211,7 @@ echo -n "File output exception handling tests: "
mkdir $CWD/output
chmod a-w $CWD/output
for f in tsTest.ts PNGTest.vo gpTest.gp vsTest.vs RGBA_voxet.vo wlTest.wl; do
coverage run -a $CONV_SCRIPT -g -r -f $CWD/output $CWD/input/$f $MODEL_INDIR/NorthGawlerConvParam.json > output.txt 2>&1
python3 -m coverage run -a $CONV_SCRIPT -g -r -f $CWD/output $CWD/input/$f $MODEL_INDIR/NorthGawlerConvParam.json > output.txt 2>&1
[ $? -ne 0 ] && echo "FAILED - test returned False $f" && exit 1
grep 'ERROR - Cannot open file' output.txt >/dev/null 2>&1 && [ $? -ne 0 ] && echo "FAILED - $f" && exit 1
done
Expand Down
27 changes: 8 additions & 19 deletions test/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@
# Remove old venv
pdm venv remove -y for-test
# Create new venv
pdm venv create --with-pip --name for-test 3.10
pdm venv create --name for-test 3.10
eval $(pdm venv activate for-test)
pip install --upgrade pip
pdm install --venv for-test

ASSIMP_VER=5.4.3
REPO_DIR=`dirname $PWD`
# NB: assimp shared library is already built as part of 'pdm install'
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$REPO_DIR/assimp-$ASSIMP_VER/bin
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"

# Install coverage
python3 -m pip install coverage defusedxml genbadge
pdm install -G test --venv for-test

# Test GOCAD import & conversion
pushd unit/gocad_import > /dev/null
Expand All @@ -26,15 +16,14 @@ python3 -m coverage run gocad_importer_test.py
[ $? -ne 0 ] && exit 1
popd > /dev/null

# Test assimp_kit
pushd unit/assimp_kit > /dev/null
coverage erase
coverage run test_assimp_kit.py
[ $? -ne 0 ] && exit 1
popd > /dev/null
## Test assimp_kit
#pushd unit/assimp_kit > /dev/null
#coverage erase
#coverage run test_assimp_kit.py
#[ $? -ne 0 ] && exit 1
#popd > /dev/null

# Test webapi
python3 -m pip install pytest httpx
pushd unit/webapi > /dev/null
coverage erase
coverage run --source webapi -m pytest
Expand Down

0 comments on commit 1caedde

Please sign in to comment.