Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/CI-unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,81 +21,118 @@
types: [published]

jobs:
check_unit_test_files:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -leo pipefail {0}

steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Python setup
uses: actions/setup-python@v6
with:
python-version: "3.12"
check-latest: true

- name: Check unit test files exist
run: |
python - <<'PY'
from pathlib import Path
src_root = Path("src/simtools")
test_root = Path("tests/unit_tests")
missing = []
for path in src_root.rglob("*.py"):
rel = path.relative_to(src_root)
if path.name in {"__init__.py", "_version.py"} or rel.parts[0] == "applications":
continue
if not (test_root / rel.parent / f"test_{path.stem}.py").exists():
missing.append(str(rel))
if missing:
raise SystemExit("Modules without unit tests:\n" + "\n".join(sorted(missing)))
PY

unit_tests:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
needs: check_unit_test_files
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: "3.12"

- os: ubuntu-latest
python-version: "3.13"
extra-args: ["sonarqube", "random-order"]

- os: ubuntu-latest
python-version: "3.14"

defaults:
run:
shell: bash -leo pipefail {0}

steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Python setup
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
check-latest: true

- name: Python dependencies
run: |
pip install -e '.[tests]'

- name: Extract SIMTOOLS_DB_SIMULATION_MODEL
run: |
SIMTOOLS_DB_SIMULATION_MODEL_VERSION=$(grep 'SIMTOOLS_DB_SIMULATION_MODEL_VERSION=' .env_template | cut -d '=' -f2- | tr -d '"')
SIMTOOLS_DB_SIMULATION_MODEL=$(grep 'SIMTOOLS_DB_SIMULATION_MODEL=' .env_template | cut -d '=' -f2- | tr -d '"')
SIMTOOLS_DB_SIMULATION_MODEL="${SIMTOOLS_DB_SIMULATION_MODEL//\'/}"
echo "SIMTOOLS_DB_SIMULATION_MODEL=$SIMTOOLS_DB_SIMULATION_MODEL" >> "$GITHUB_ENV"
echo "SIMTOOLS_DB_SIMULATION_MODEL_VERSION=$SIMTOOLS_DB_SIMULATION_MODEL_VERSION" >> "$GITHUB_ENV"
echo "Simulation model set to: $SIMTOOLS_DB_SIMULATION_MODEL version $SIMTOOLS_DB_SIMULATION_MODEL_VERSION"

- name: Unit tests
shell: bash -l {0}
env:
SIMTOOLS_DB_SIMULATION_MODEL: ${{ env.SIMTOOLS_DB_SIMULATION_MODEL }}
SIMTOOLS_DB_SIMULATION_MODEL_VERSION: ${{ env.SIMTOOLS_DB_SIMULATION_MODEL_VERSION }}
run: |
pytest --durations=10 --color=yes -n 4 --dist loadscope \
--cov=simtools --cov-report=xml --retries 2 --retry-delay 5

# CTAO-DPPS-SonarQube
- uses: SonarSource/sonarqube-scan-action@v8.0.0
if: contains(matrix.extra-args, 'sonarqube')
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=gammasim_simtools_0d23837b-8b2d-4e54-9a98-2f1bde681f14
-Dsonar.host.url=https://sonar-ctao.zeuthen.desy.de
-Dsonar.qualitygate.wait=true
-Dsonar.python.coverage.reportPaths=coverage.xml
-Dsonar.python.version=${{ matrix.python-version }}
-Dsonar.exclusions=**/docs/**,src/simtools/applications/**,**/__init__.py
-Dsonar.coverage.exclusions=**/tests/**,src/simtools/applications/**

- name: Random order
if: github.event_name == 'schedule' && contains(matrix.extra-args, 'random-order')
shell: bash -l {0}
env:
SIMTOOLS_DB_SIMULATION_MODEL: ${{ env.SIMTOOLS_DB_SIMULATION_MODEL }}
SIMTOOLS_DB_SIMULATION_MODEL_VERSION: ${{ env.SIMTOOLS_DB_SIMULATION_MODEL_VERSION }}
run: |
pytest --color=yes -n 4 --dist loadscope --count 5 --random-order \
--retries 2 --retry-delay 5

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
1 change: 1 addition & 0 deletions docs/changes/2193.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add CI tests to ensure that every simtools Python module has a corresponding unit test module.
23 changes: 23 additions & 0 deletions tests/unit_tests/configuration/test_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import simtools.configuration.defaults as defaults


def test_corsika_defaults():
"""Test default CORSIKA configuration constants."""
assert defaults.CORSIKA_PATH == "/workdir/simulation_software/corsika7"
assert (
defaults.CORSIKA_INTERACTION_TABLE_PATH
== "/workdir/external/simpipe/simulation_software/corsika7-interaction-tables/interaction-tables/"
)
assert defaults.CORSIKA_HE_INTERACTION == "epos"
assert defaults.CORSIKA_LE_INTERACTION == "urqmd"


def test_simulation_software_defaults():
"""Test simulation software default values."""
assert defaults.CURVED_ATMOSPHERE_MIN_ZENITH_ANGLE_DEG == 65
assert defaults.SIMULATION_SOFTWARE_CHOICES == (
"corsika",
"sim_telarray",
"corsika_sim_telarray",
)
assert defaults.SIMULATION_SOFTWARE_DEFAULT == "corsika_sim_telarray"