From 812a5fd7af9a98c1ffdb94f5a863065df0828ed7 Mon Sep 17 00:00:00 2001 From: Goran Jelic-Cizmek Date: Mon, 26 Feb 2024 10:37:04 +0100 Subject: [PATCH] Update test-command and test script --- packaging/test_wheel.bash | 64 ++++++++++++++++++++++++++++++++++----- pyproject.toml | 2 +- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/packaging/test_wheel.bash b/packaging/test_wheel.bash index b97fc6a165..8e85b2aed0 100755 --- a/packaging/test_wheel.bash +++ b/packaging/test_wheel.bash @@ -1,9 +1,59 @@ -#!/bin/bash +#!/usr/bin/env bash # A simple set of tests checking if a wheel is working correctly -set -xe +set -eux -python -m pytest "$1/test/unit/pybind" -find "$1/test/" "$1/nmodl/ext/" \ - -name "*.mod" \ - -exec nmodl '{}' sympy --analytic \; \ - -exec python -c "import nmodl; driver = nmodl.NmodlDriver(); driver.parse_file('{}')" \; +this_dir="$(dirname "$(realpath "$0")")" + +if [ "$#" -lt 2 ]; then + echo "Usage: $(basename "$0") python_exe python_wheel [use_virtual_env]" + exit 1 +fi + +# cli parameters +python_exe=$1 +python_wheel=$2 +use_venv=$3 #if $3 is not "false" then use virtual environment + +python_ver=$("$python_exe" -c "import sys; print('%d%d' % tuple(sys.version_info)[:2])") + + +test_wheel () { + # sample mod file for nrnivmodl check + 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 -o "${OUTPUT_DIR}" "${mod}" sympy --analytic + $python_exe -c "import nmodl; driver = nmodl.NmodlDriver(); driver.parse_file('${mod}')" + done + $python_exe -m pytest -vvv "${this_dir}/../test/" +} + +echo "== Testing $python_wheel using $python_exe ($python_ver) ==" + +# 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="$(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}[test]" +$python_exe -m pip show nmodl || $python_exe -m pip show nmodl-nightly + +# run tests +test_wheel "$(command -v python)" + +# cleanup +if [[ "$use_venv" != "false" ]]; then + deactivate +fi diff --git a/pyproject.toml b/pyproject.toml index 3e4f647a7e..9f64cabe6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ NMODL_BUILD_WHEEL = "ON" skip = ["pp*", "*-win32", "*-manylinux_i686", "*-musllinux_i686", "*-musllinux_x86_64", "*-musllinux_aarch64"] test-extras = ["test"] test-command = [ - "bash {package}/packaging/test_wheel.bash {package}", + "bash {package}/packaging/test_wheel.bash python3 {wheel} false", ] build = ["cp311*"]