diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index ec25b003..5ae4751f 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -7,10 +7,12 @@ on: workflow_dispatch: {} push: branches: - - master + - '**' paths: - 'fdsreader/**' pull_request: + branches: + - '**' paths: - 'fdsreader/**' @@ -20,13 +22,18 @@ permissions: jobs: run-tests: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13'] + + name: Python ${{ matrix.python-version }} tests steps: - uses: actions/checkout@v4 with: lfs: true - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/tests/acceptance_tests/test_version_compatibility.py b/tests/acceptance_tests/test_version_compatibility.py new file mode 100644 index 00000000..115d0193 --- /dev/null +++ b/tests/acceptance_tests/test_version_compatibility.py @@ -0,0 +1,8 @@ +"""Basic tests to ensure version compatibility.""" + +from fdsreader import Simulation + + +def test_sim(): + sim = Simulation("test.smv") + assert sim.chid == "test" diff --git a/tests/test.smv b/tests/cases/test.smv similarity index 100% rename from tests/test.smv rename to tests/cases/test.smv diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100755 index 00000000..a092a18f --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,80 @@ +#!/bin/bash +set -euo pipefail + +PYTEST_ARGS="-v -W ignore::UserWarning" + +# Get the tests directory (where this script is located) +TESTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJECT_ROOT="$( cd "$TESTS_DIR/.." && pwd )" + + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Detect Python environment manager +if command_exists uv; then + PYTHON_CMD="uv run" +elif command_exists python3; then + PYTHON_CMD="python3 -m" +elif command_exists python; then + PYTHON_CMD="python -m" +else + echo "Error: No Python interpreter found (install uv or python3)" >&2 + exit 1 +fi + +echo "" +echo -e "Preparing test data..." +cd "$TESTS_DIR/cases" || { echo -e "${RED} Cannot cd to $TESTS_DIR/cases${NC}"; exit 1; } + +shopt -s nullglob + +EXPECTED_DIRS=() +for f in *.tgz; do + [[ -f "$f" ]] || continue + EXPECTED_DIRS+=("${f%.tgz}") +done + +NEED_EXTRACT=false + +# Check if any expected directory is missing +for tgz_file in *.tgz; do + if [ -f "$tgz_file" ]; then + DIR_NAME="${tgz_file%.tgz}" + if [ ! -d "$DIR_NAME" ]; then + NEED_EXTRACT=true + break + fi + fi +done + +if [ "$NEED_EXTRACT" = true ]; then + echo " Extracting test data files..." + for f in *.tgz; do + if [ -f "$f" ]; then + echo " Extracting $f..." + tar -xzf "$f" + if [ $? -ne 0 ]; then + echo -e "Failed to extract $f$" + exit 1 + fi + fi + done + echo -e "Test data extracted" +else + echo -e "Test data already extracted" +fi + +echo "" +echo -e "Running acceptance tests..." +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + + +# Run the tests +if command_exists uv; then + uv run pytest ../acceptance_tests/ $PYTEST_ARGS +else + $PYTHON_CMD pytest ../acceptance_tests/ $PYTEST_ARGS +fi diff --git a/tests/test_version_compatibility.py b/tests/test_version_compatibility.py deleted file mode 100644 index 8ca7595a..00000000 --- a/tests/test_version_compatibility.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Basic tests to ensure version compatibility. -""" - -import unittest - -from fdsreader import Simulation - - -class SimTest(unittest.TestCase): - def test_sim(self): - sim = Simulation(".") - self.assertEqual(sim.chid, "test") - - -if __name__ == '__main__': - unittest.main()