Skip to content
65 changes: 63 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,73 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install ngspice
run: |
sudo apt-get update
sudo apt-get install ngspice
- name: Install dependencies
run: |
pipx install uv
uv pip install --system pytest
sudo apt-get update
sudo apt-get install ngspice
uv pip install --system -e .[all]
- name: Full Python tests
run: |
pytest -s

windows-test:
runs-on: windows-latest
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install ngspice
shell: powershell
run: |
curl.exe -L -o ngspice.7z "https://downloads.sourceforge.net/project/ngspice/ng-spice-rework/44.2/ngspice-44.2_64.7z"

7z x ngspice.7z -o"C:\Program Files"

Remove-Item ngspice.7z
"C:\Program Files\Spice64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install uv
uv pip install --system pytest
uv pip install --system -e .[all]

- name: Full Python tests
run: |
pytest -s

macos-test:
runs-on: macos-latest
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install ngspice
run: |
brew install ngspice # for power electronics problems
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install uv
uv pip install --system pytest
uv pip install --system -e .[all]
- name: Full Python tests
run: |
Expand Down
3 changes: 2 additions & 1 deletion engibench/problems/power_electronics/utils/ngspice.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _get_ngspice_path(self) -> str:
# Look for ngspice in Spice64 folder and common install locations
possible_paths = [
self.ngspice_windows_path,
"ngspice.exe",
os.path.normpath(os.path.join("C:/Program Files/Spice64/bin/ngspice.exe")),
os.path.normpath(os.path.join("C:/Program Files (x86)/ngspice/bin/ngspice.exe")),
]
Expand All @@ -47,7 +48,7 @@ def _get_ngspice_path(self) -> str:
ngspice_path = possible_paths[0] # Default to first path if none found
if ngspice_path is None or not os.path.exists(ngspice_path):
raise FileNotFoundError(
f"ngspice.exe not found at {ngspice_path}. You can download it from https://sourceforge.net/projects/ngspice/files/ng-spice-rework/44.2/"
f"ngspice.exe not found at {ngspice_path}. You can download it from https://sourceforge.net/projects/ngspice/files/ng-spice-rework/44.2/. You can also see our GitHub Actions workflow (test.yml) for how to automatically install it."
)
return ngspice_path
if self.system in ["darwin", "linux"]:
Expand Down
4 changes: 4 additions & 0 deletions tests/utils/test_container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import pytest

from engibench.utils import container
Expand All @@ -6,13 +8,15 @@


@pytest.mark.parametrize("runtime", available_runtimes)
@pytest.mark.skipif(sys.platform == "win32", reason="Skip Singularity tests on Windows")
def test_run_singularity_sets_correct_environment(runtime: type[container.ContainerRuntime]) -> None:
"""Test if singularity can run a container with an environment variable."""

runtime.run(command=["sh", "-c", "[ $TEST_VAR = test ]"], env={"TEST_VAR": "test"}, image="alpine").check_returncode()


@pytest.mark.parametrize("runtime", available_runtimes)
@pytest.mark.skipif(sys.platform == "win32", reason="Skip Singularity tests on Windows")
def test_run_singularity_mounts_files(runtime: type[container.ContainerRuntime]) -> None:
"""Test if singularity can run a container with a mount."""

Expand Down
Loading