Skip to content

Commit

Permalink
Refactor testing of wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
JCGoran committed Feb 26, 2024
1 parent bc913ef commit a1165c5
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions packaging/test_wheel.bash
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/bin/bash
#!/usr/bin/env bash
# A simple set of tests checking if a wheel is working correctly
set -xe
set -eux

if [ ! -f setup.py ]; then
echo "Error: Please launch $0 from the root dir"
exit 1
fi
this_dir="$(dirname "$(realpath "$0")")"

if [ "$#" -lt 2 ]; then
echo "Usage: $(basename $0) python_exe python_wheel [use_virtual_env]"
echo "Usage: $(basename "$0") python_exe python_wheel [use_virtual_env]"
exit 1
fi

Expand All @@ -22,49 +19,41 @@ python_ver=$("$python_exe" -c "import sys; print('%d%d' % tuple(sys.version_info

test_wheel () {
# sample mod file for nrnivmodl check
local TEST_DIR="test_dir"
mkdir -p $TEST_DIR
cp ../nmodl/ext/example/*.mod $TEST_DIR/
cp ../test/integration/mod/cabpump.mod ../test/integration/mod/var_init.inc $TEST_DIR/
cd $TEST_DIR
for mod in *.mod
TEST_DIR="$(mktemp -d)"
OUTPUT_DIR="$(mktemp -d)"
cp "${this_dir}/../nmodl/ext/example/"*.mod "$TEST_DIR/"
cp "${this_dir}/../test/integration/mod/cabpump.mod" "${this_dir}/../test/integration/mod/var_init.inc" "$TEST_DIR/"
for mod in "${TEST_DIR}/"*.mod
do
nmodl $mod sympy --analytic
nmodl -o "${OUTPUT_DIR}" "${mod}" sympy --analytic
$python_exe -c "import nmodl; driver = nmodl.NmodlDriver(); driver.parse_file('${mod}')"
done
$python_exe -c "import nmodl; driver = nmodl.NmodlDriver(); driver.parse_file('hh.mod')"
cd ..
#clean-up
rm -rf $TEST_DIR
$python_exe -m pytest -vvv "${this_dir}/../test/"
}

echo "== Testing $python_wheel using $python_exe ($python_ver) =="

mkdir testwheel && cd testwheel

# creat python virtual environment and use `python` as binary name
# because it will be correct one from venv.
if [[ "$use_venv" != "false" ]]; then
echo " == Creating virtual environment == "
venv_name="nmodl_test_venv_${python_ver}"
$python_exe -m venv $venv_name
. $venv_name/bin/activate
python_exe=`which python`
venv_name="$(mktemp -d)/nmodl_test_venv_${python_ver}"
$python_exe -m venv "$venv_name"
. "$venv_name/bin/activate"
python_exe="$(command -v python)"
else
echo " == Using global install == "
fi

# install nmodl
$python_exe -m pip install -U pip
$python_exe -m pip install ../$python_wheel
$python_exe -m pip install "${python_wheel}[test]"
$python_exe -m pip show nmodl || $python_exe -m pip show nmodl-nightly

# run tests
test_wheel $(which python)
test_wheel "$(command -v python)"

# cleanup
if [[ "$use_venv" != "false" ]]; then
deactivate
fi

rm -rf $venv_name
echo "Removed $venv_name"

0 comments on commit a1165c5

Please sign in to comment.