From fd65e9423e2c3467d605202950d98cd0ef1226b0 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Fri, 7 Nov 2025 17:34:27 +0100 Subject: [PATCH 1/6] Create script to run tests - Moved one test to the directory along other tests - Moved its fds file to the directory with data - This is just to keep the directory clean. --- .../test_version_compatibility.py | 7 +- tests/{ => cases}/test.smv | 0 tests/run_tests.sh | 218 ++++++++++++++++++ 3 files changed, 221 insertions(+), 4 deletions(-) rename tests/{ => acceptance_tests}/test_version_compatibility.py (61%) rename tests/{ => cases}/test.smv (100%) create mode 100755 tests/run_tests.sh diff --git a/tests/test_version_compatibility.py b/tests/acceptance_tests/test_version_compatibility.py similarity index 61% rename from tests/test_version_compatibility.py rename to tests/acceptance_tests/test_version_compatibility.py index 8ca7595a..1146772b 100644 --- a/tests/test_version_compatibility.py +++ b/tests/acceptance_tests/test_version_compatibility.py @@ -1,5 +1,4 @@ -"""Basic tests to ensure version compatibility. -""" +"""Basic tests to ensure version compatibility.""" import unittest @@ -8,9 +7,9 @@ class SimTest(unittest.TestCase): def test_sim(self): - sim = Simulation(".") + sim = Simulation("test") self.assertEqual(sim.chid, "test") -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() 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..cb435a3c --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,218 @@ +#!/bin/bash +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +# 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 show help +show_help() { + echo -e "${BLUE}FDSreader Test Runner${NC}" + echo "" + echo "Usage: $0 [OPTIONS] [PYTEST_ARGS]" + echo "" + echo "Run FDSreader acceptance tests with automatic setup and data extraction." + echo "" + echo -e "${CYAN}Options:${NC}" + echo " -h, --help Show this help message and exit" + echo " -f, --force-extract Force re-extraction of test data from .tgz files" + echo "" + echo -e "${CYAN}Examples:${NC}" + echo " $0 Run all tests with default settings" + echo " $0 -v Run tests in verbose mode" + echo " $0 -f Force re-extract data and run tests" + echo " $0 -x Stop on first test failure" + echo " $0 -k test_bndf Run only tests matching 'test_bndf'" + echo " $0 --tb=short Use shorter traceback format" + echo " $0 -f -v -x Combine multiple options" + echo "" + echo -e "${CYAN}Common pytest arguments:${NC}" + echo " -v, --verbose Increase verbosity" + echo " -q, --quiet Decrease verbosity" + echo " -x, --exitfirst Exit on first failure" + echo " -k EXPRESSION Run tests matching expression" + echo " --tb=style Traceback style (short/long/native/no)" + echo " --lf Run last failed tests" + echo " --ff Run failed tests first" + echo " -s Don't capture stdout (show print statements)" + echo " --collect-only Only collect tests, don't run them" + echo "" + echo -e "${CYAN}What this script does:${NC}" + echo " 1. Installs dependencies (pytest, numpy, fdsreader)" + echo " 2. Extracts test data from .tgz files if needed" + echo " 3. Runs acceptance tests from the correct directory" + echo " 4. Reports test results with colored output" + echo "" + echo -e "${CYAN}Note:${NC} Test data is cached after extraction. Use -f to force re-extraction." +} + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Parse command line arguments +FORCE_EXTRACT=false +PYTEST_ARGS="" + +while [[ $# -gt 0 ]]; do + case "$1" in + -h|--help) + show_help + exit 0 + ;; + -f|--force-extract) + FORCE_EXTRACT=true + shift + ;; + *) + PYTEST_ARGS="$PYTEST_ARGS $1" + shift + ;; + esac +done + +# Default to verbose if no pytest args provided +if [ -z "$PYTEST_ARGS" ]; then + PYTEST_ARGS="-v" +fi + +echo -e "${BLUE}╔══════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ FDSreader Acceptance Test Runner ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════╝${NC}" +echo "" + +# Detect Python environment manager +if command_exists uv; then + PYTHON_CMD="uv run" + PIP_INSTALL="uv pip install" + echo -e "${GREEN} Using uv for Python environment${NC}" +elif command_exists python3; then + PYTHON_CMD="python3 -m" + PIP_INSTALL="python3 -m pip install" + echo -e "${YELLOW} Using system python3 (consider using uv)${NC}" +elif command_exists python; then + PYTHON_CMD="python -m" + PIP_INSTALL="python -m pip install" + echo -e "${YELLOW} Using system python${NC}" +else + echo -e "${RED} Error: No Python interpreter found${NC}" + exit 1 +fi + +# Step 1: Install dependencies +echo "" +echo -e "${GREEN}Step 1: Installing dependencies...${NC}" + +# Install pytest and numpy +$PIP_INSTALL pytest numpy > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo -e "${RED} Failed to install pytest and numpy${NC}" + echo -e "${YELLOW} Try running: $PIP_INSTALL pytest numpy${NC}" + exit 1 +fi + +# Install fdsreader package in editable mode from project root +cd "$PROJECT_ROOT" +$PIP_INSTALL -e . > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo -e "${RED} Failed to install fdsreader package${NC}" + echo -e "${YELLOW} Try running: $PIP_INSTALL -e .${NC}" + exit 1 +fi +echo -e "${GREEN} Dependencies installed${NC}" + +# Step 2: Extract test data if needed +echo "" +echo -e "${GREEN}Step 2: Preparing test data...${NC}" +cd "$TESTS_DIR/cases" || { echo -e "${RED} Cannot cd to $TESTS_DIR/cases${NC}"; exit 1; } + +# Make globs like *.tgz expand to nothing (not the literal string) if no match +shopt -s nullglob + +# Build EXPECTED_DIRS dynamically from available .tgz files +EXPECTED_DIRS=() +for f in *.tgz; do + [[ -f "$f" ]] || continue + EXPECTED_DIRS+=("${f%.tgz}") +done + +# Check if we need to extract +NEED_EXTRACT=false + +if [ "$FORCE_EXTRACT" = true ]; then + echo " Force extraction requested, cleaning old data..." + # Remove existing extracted directories + for dir in "${EXPECTED_DIRS[@]}"; do + if [ -d "$dir" ]; then + rm -rf "$dir" + fi + done + NEED_EXTRACT=true +else + # 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 +fi + +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 "${RED}✗ Failed to extract $f${NC}" + exit 1 + fi + fi + done + echo -e "${GREEN} Test data extracted${NC}" +else + echo -e "${GREEN} Test data already extracted (use -f to force re-extract)${NC}" +fi + +# Step 3: Run tests +echo "" +echo -e "${GREEN}Step 3: Running acceptance tests...${NC}" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +# Run from cases directory (where test data is located) +cd "$TESTS_DIR/cases" + +# Run the tests +if command_exists uv; then + uv run pytest ../acceptance_tests/ $PYTEST_ARGS +else + $PYTHON_CMD pytest ../acceptance_tests/ $PYTEST_ARGS +fi + +TEST_RESULT=$? + +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +# Step 4: Report results +if [ $TEST_RESULT -eq 0 ]; then + echo -e "${GREEN} All tests passed!${NC}" +else + echo -e "${RED} Tests failed (exit code: $TEST_RESULT)${NC}" + echo "" + echo -e "${YELLOW}Tip: Use '$0 --lf' to rerun only failed tests${NC}" +fi + +exit $TEST_RESULT From e94392ab8257db33afefcacd3ecf6f477b569db7 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Fri, 7 Nov 2025 17:35:46 +0100 Subject: [PATCH 2/6] Run ci with different python versions --- .github/workflows/testsuite.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index ec25b003..a3f1592f 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -20,13 +20,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 From 10b922ada48c599718dde92fabd88a5fc0443652 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Sat, 8 Nov 2025 18:10:18 +0100 Subject: [PATCH 3/6] Minimal script - Detect used python manager - Add pytest args --- tests/run_tests.sh | 169 +++++---------------------------------------- 1 file changed, 16 insertions(+), 153 deletions(-) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index cb435a3c..ae884b6c 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,174 +1,54 @@ #!/bin/bash set -euo pipefail -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -CYAN='\033[0;36m' -NC='\033[0m' # No Color +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 show help -show_help() { - echo -e "${BLUE}FDSreader Test Runner${NC}" - echo "" - echo "Usage: $0 [OPTIONS] [PYTEST_ARGS]" - echo "" - echo "Run FDSreader acceptance tests with automatic setup and data extraction." - echo "" - echo -e "${CYAN}Options:${NC}" - echo " -h, --help Show this help message and exit" - echo " -f, --force-extract Force re-extraction of test data from .tgz files" - echo "" - echo -e "${CYAN}Examples:${NC}" - echo " $0 Run all tests with default settings" - echo " $0 -v Run tests in verbose mode" - echo " $0 -f Force re-extract data and run tests" - echo " $0 -x Stop on first test failure" - echo " $0 -k test_bndf Run only tests matching 'test_bndf'" - echo " $0 --tb=short Use shorter traceback format" - echo " $0 -f -v -x Combine multiple options" - echo "" - echo -e "${CYAN}Common pytest arguments:${NC}" - echo " -v, --verbose Increase verbosity" - echo " -q, --quiet Decrease verbosity" - echo " -x, --exitfirst Exit on first failure" - echo " -k EXPRESSION Run tests matching expression" - echo " --tb=style Traceback style (short/long/native/no)" - echo " --lf Run last failed tests" - echo " --ff Run failed tests first" - echo " -s Don't capture stdout (show print statements)" - echo " --collect-only Only collect tests, don't run them" - echo "" - echo -e "${CYAN}What this script does:${NC}" - echo " 1. Installs dependencies (pytest, numpy, fdsreader)" - echo " 2. Extracts test data from .tgz files if needed" - echo " 3. Runs acceptance tests from the correct directory" - echo " 4. Reports test results with colored output" - echo "" - echo -e "${CYAN}Note:${NC} Test data is cached after extraction. Use -f to force re-extraction." -} # Function to check if a command exists command_exists() { command -v "$1" >/dev/null 2>&1 } -# Parse command line arguments -FORCE_EXTRACT=false -PYTEST_ARGS="" - -while [[ $# -gt 0 ]]; do - case "$1" in - -h|--help) - show_help - exit 0 - ;; - -f|--force-extract) - FORCE_EXTRACT=true - shift - ;; - *) - PYTEST_ARGS="$PYTEST_ARGS $1" - shift - ;; - esac -done - -# Default to verbose if no pytest args provided -if [ -z "$PYTEST_ARGS" ]; then - PYTEST_ARGS="-v" -fi - -echo -e "${BLUE}╔══════════════════════════════════════╗${NC}" -echo -e "${BLUE}║ FDSreader Acceptance Test Runner ║${NC}" -echo -e "${BLUE}╚══════════════════════════════════════╝${NC}" -echo "" - # Detect Python environment manager if command_exists uv; then PYTHON_CMD="uv run" - PIP_INSTALL="uv pip install" - echo -e "${GREEN} Using uv for Python environment${NC}" elif command_exists python3; then PYTHON_CMD="python3 -m" - PIP_INSTALL="python3 -m pip install" - echo -e "${YELLOW} Using system python3 (consider using uv)${NC}" elif command_exists python; then PYTHON_CMD="python -m" - PIP_INSTALL="python -m pip install" - echo -e "${YELLOW} Using system python${NC}" else - echo -e "${RED} Error: No Python interpreter found${NC}" - exit 1 -fi - -# Step 1: Install dependencies -echo "" -echo -e "${GREEN}Step 1: Installing dependencies...${NC}" - -# Install pytest and numpy -$PIP_INSTALL pytest numpy > /dev/null 2>&1 -if [ $? -ne 0 ]; then - echo -e "${RED} Failed to install pytest and numpy${NC}" - echo -e "${YELLOW} Try running: $PIP_INSTALL pytest numpy${NC}" - exit 1 -fi - -# Install fdsreader package in editable mode from project root -cd "$PROJECT_ROOT" -$PIP_INSTALL -e . > /dev/null 2>&1 -if [ $? -ne 0 ]; then - echo -e "${RED} Failed to install fdsreader package${NC}" - echo -e "${YELLOW} Try running: $PIP_INSTALL -e .${NC}" + echo "Error: No Python interpreter found (install uv or python3)" >&2 exit 1 fi -echo -e "${GREEN} Dependencies installed${NC}" -# Step 2: Extract test data if needed echo "" -echo -e "${GREEN}Step 2: Preparing test data...${NC}" +echo -e "Preparing test data..." cd "$TESTS_DIR/cases" || { echo -e "${RED} Cannot cd to $TESTS_DIR/cases${NC}"; exit 1; } -# Make globs like *.tgz expand to nothing (not the literal string) if no match shopt -s nullglob -# Build EXPECTED_DIRS dynamically from available .tgz files EXPECTED_DIRS=() for f in *.tgz; do [[ -f "$f" ]] || continue EXPECTED_DIRS+=("${f%.tgz}") done -# Check if we need to extract NEED_EXTRACT=false -if [ "$FORCE_EXTRACT" = true ]; then - echo " Force extraction requested, cleaning old data..." - # Remove existing extracted directories - for dir in "${EXPECTED_DIRS[@]}"; do - if [ -d "$dir" ]; then - rm -rf "$dir" - fi - done - NEED_EXTRACT=true -else - # 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 +# 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 - done -fi + fi +done if [ "$NEED_EXTRACT" = true ]; then echo " Extracting test data files..." @@ -177,22 +57,20 @@ if [ "$NEED_EXTRACT" = true ]; then echo " Extracting $f..." tar -xzf "$f" if [ $? -ne 0 ]; then - echo -e "${RED}✗ Failed to extract $f${NC}" + echo -e "Failed to extract $f$" exit 1 fi fi done - echo -e "${GREEN} Test data extracted${NC}" + echo -e "Test data extracted" else - echo -e "${GREEN} Test data already extracted (use -f to force re-extract)${NC}" + echo -e "Test data already extracted" fi -# Step 3: Run tests echo "" -echo -e "${GREEN}Step 3: Running acceptance tests...${NC}" +echo -e "Running acceptance tests..." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -# Run from cases directory (where test data is located) cd "$TESTS_DIR/cases" # Run the tests @@ -201,18 +79,3 @@ if command_exists uv; then else $PYTHON_CMD pytest ../acceptance_tests/ $PYTEST_ARGS fi - -TEST_RESULT=$? - -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - -# Step 4: Report results -if [ $TEST_RESULT -eq 0 ]; then - echo -e "${GREEN} All tests passed!${NC}" -else - echo -e "${RED} Tests failed (exit code: $TEST_RESULT)${NC}" - echo "" - echo -e "${YELLOW}Tip: Use '$0 --lf' to rerun only failed tests${NC}" -fi - -exit $TEST_RESULT From 4773c26ea301a606942fed4f11ad47ea18d96108 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Sat, 8 Nov 2025 18:25:36 +0100 Subject: [PATCH 4/6] simplify test since pytest is being used. --- .../acceptance_tests/test_version_compatibility.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/acceptance_tests/test_version_compatibility.py b/tests/acceptance_tests/test_version_compatibility.py index 1146772b..5d3ec850 100644 --- a/tests/acceptance_tests/test_version_compatibility.py +++ b/tests/acceptance_tests/test_version_compatibility.py @@ -1,15 +1,8 @@ """Basic tests to ensure version compatibility.""" -import unittest - from fdsreader import Simulation -class SimTest(unittest.TestCase): - def test_sim(self): - sim = Simulation("test") - self.assertEqual(sim.chid, "test") - - -if __name__ == "__main__": - unittest.main() +def test_sim(): + sim = Simulation("cases/test.smv") + assert sim.chid == "test" From e04262cf42e04cf18dd9f2b697db5fb08dc998f6 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Sat, 8 Nov 2025 18:31:51 +0100 Subject: [PATCH 5/6] remove unneeded cd --- tests/acceptance_tests/test_version_compatibility.py | 2 +- tests/run_tests.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/acceptance_tests/test_version_compatibility.py b/tests/acceptance_tests/test_version_compatibility.py index 5d3ec850..115d0193 100644 --- a/tests/acceptance_tests/test_version_compatibility.py +++ b/tests/acceptance_tests/test_version_compatibility.py @@ -4,5 +4,5 @@ def test_sim(): - sim = Simulation("cases/test.smv") + sim = Simulation("test.smv") assert sim.chid == "test" diff --git a/tests/run_tests.sh b/tests/run_tests.sh index ae884b6c..a092a18f 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -71,7 +71,6 @@ echo "" echo -e "Running acceptance tests..." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -cd "$TESTS_DIR/cases" # Run the tests if command_exists uv; then From e83621e95219339c93152dcd2ac1e59e78009891 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi Date: Sat, 8 Nov 2025 18:39:04 +0100 Subject: [PATCH 6/6] run ci for PR also --- .github/workflows/testsuite.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index a3f1592f..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/**'