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
23 changes: 13 additions & 10 deletions .github/workflows/process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ permissions:
pages: write
id-token: write

env:
python-version: '3.10'

jobs:
unit-test:
strategy:
Expand Down Expand Up @@ -40,9 +43,9 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- name: Run integration tests
run: hatch run test-default:tests tests/integration
run: hatch run test.py${{ env.python-version }}:tests-integration

example-test:
runs-on: ubuntu-latest
Expand All @@ -51,9 +54,9 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- name: Run example tests
run: hatch run test-default:tests tests/examples
run: hatch run test.py${{ env.python-version }}:tests-examples

regression-test:
runs-on: ubuntu-latest
Expand All @@ -71,9 +74,9 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- name: Run regression tests
run: hatch run test-default:tests tests/regression --reg-tolerance=${{ matrix.tolerance }}
run: hatch run test.py${{ env.python-version }}:tests-regression --reg-tolerance=${{ matrix.tolerance }}

run-tracking-inputs:
runs-on: ubuntu-latest
Expand All @@ -83,7 +86,7 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- name: Run regression input files
run: hatch run python tracking/run_tracking_inputs.py run tests/regression/input_files
- name: Move other files
Expand All @@ -106,7 +109,7 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- name: Run pre-commit
run: hatch run lint:fmt

Expand All @@ -124,7 +127,7 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- name: Setup SSH identity
uses: webfactory/ssh-agent@v0.7.0
with:
Expand Down Expand Up @@ -174,7 +177,7 @@ jobs:
- name: Setup python and hatch
uses: Fusion-Power-Plant-Framework/fppf-actions/setup-hatch@main
with:
python-version: '3.10'
python-version: ${{ env.python-version }}
- run: hatch run python scripts/vardes.py
- run: git config --global --add safe.directory '*'
- name: Download STF_TF.json files
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '4', --offset, '2']

- repo: https://github.com/biomejs/pre-commit
rev: v2.3.8
hooks:
- id: biome-format
types: [json]
args: [--indent-style=space, --indent-width=2, --line-width=89]

- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
hooks:
Expand Down
46 changes: 23 additions & 23 deletions examples/data/mfile_to_csv_vars.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"vars": [
"minmax",
"p_hcd_injected_max",
"p_plant_electric_net_required_mw",
"ripple_b_tf_plasma_edge_max",
"t_burn_min",
"alstroh",
"sig_tf_wp_max",
"dx_tf_turn_steel",
"f_j_cs_start_pulse_end_flat_top",
"alstroh",
"rmajor",
"dr_tf_inboard",
"dr_cs",
"c_tf_turn",
"dr_tf_wp_with_insulation",
"dr_cryostat",
"dr_shld_outboard",
"dz_divertor",
"rmajor"
]
}
{
"vars": [
"minmax",
"p_hcd_injected_max",
"p_plant_electric_net_required_mw",
"ripple_b_tf_plasma_edge_max",
"t_burn_min",
"alstroh",
"sig_tf_wp_max",
"dx_tf_turn_steel",
"f_j_cs_start_pulse_end_flat_top",
"alstroh",
"rmajor",
"dr_tf_inboard",
"dr_cs",
"c_tf_turn",
"dr_tf_wp_with_insulation",
"dr_cryostat",
"dr_shld_outboard",
"dz_divertor",
"rmajor"
]
}
6 changes: 3 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ nav:
- Python Optimisation and Numba: development/numba.md
- Style:
- Standards: development/standards.md
# - Versioning: development/versioning.md
# - Versioning: development/versioning.md
- Models:
- Physics Models:
- Plasma:
Expand Down Expand Up @@ -147,15 +147,15 @@ repo_name: UKAEA/PROCESS
copyright: Copyright © 2023 United Kingdom Atomic Energy Authority

theme:
# name: readthedocs
# name: readthedocs
name: material
font:
text: Roboto
features:
- navigation.tabs
- navigation.footer
- navigation.top
# - navigation.sections
# - navigation.sections
- search.suggest
- search.highlight
- navigation.instant
Expand Down
46 changes: 23 additions & 23 deletions process/io/mfile_to_csv_vars.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"vars": [
"minmax",
"p_hcd_injected_max",
"p_plant_electric_net_required_mw",
"ripple_b_tf_plasma_edge_max",
"t_burn_min",
"alstroh",
"sig_tf_wp_max",
"dx_tf_turn_steel",
"f_j_cs_start_pulse_end_flat_top",
"alstroh",
"rmajor",
"dr_tf_inboard",
"dr_cs",
"c_tf_turn",
"dr_tf_wp_with_insulation",
"dr_cryostat",
"dr_shld_outboard",
"dz_divertor",
"rmajor"
]
}
{
"vars": [
"minmax",
"p_hcd_injected_max",
"p_plant_electric_net_required_mw",
"ripple_b_tf_plasma_edge_max",
"t_burn_min",
"alstroh",
"sig_tf_wp_max",
"dx_tf_turn_steel",
"f_j_cs_start_pulse_end_flat_top",
"alstroh",
"rmajor",
"dr_tf_inboard",
"dr_cs",
"c_tf_turn",
"dr_tf_wp_with_insulation",
"dr_cryostat",
"dr_shld_outboard",
"dz_divertor",
"rmajor"
]
}
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ features = ["test"]
python = ["3.10", "3.11", "3.12", "3.13"]
[tool.hatch.envs.test.scripts]
tests = "pytest -n auto -v {args:tests}"
tests-cov = "pytest --cov process --cov-report html:htmlcov --cov-report xml {args:tests}"
tests-cov-private = "pytest --private --cov process --cov-report html:htmlcov --cov-report xml {args:tests}"

[tool.hatch.envs.test-default]
template="test"
[[tool.hatch.envs.test-default.matrix]]
python = ["3.10"]

tests-unit = "pytest -n auto -v tests/unit {args:}"
tests-regression = "pytest -n auto -v tests/regression {args:}"
tests-integration = "pytest -n auto -v tests/integration {args:}"
tests-examples = "pytest -n auto -v tests/examples {args:}"
tests-cov = "pytest -n auto --cov process --cov-report html:htmlcov --cov-report xml {args:tests}"

[tool.hatch.envs.docs]
features = ["docs"]
Expand All @@ -122,6 +119,9 @@ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

[tool.pytest.ini_options]
addopts = "--strict-markers -r fEX"
markers = [
"classplot: Show and close figures after running all tests in class",
]

[tool.ty.terminal]
output-format = "concise"
Expand Down
64 changes: 64 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import warnings

import matplotlib as mpl
import pytest
from _pytest.fixtures import SubRequest
from system_check import system_compatible
Expand Down Expand Up @@ -39,6 +40,21 @@ def pytest_addoption(parser):
default=False,
help="Only regression test optimisation parameters: useful for solver comparisons",
)
parser.addoption(
"--plotting-on",
action="store_true",
default=False,
help="switch on interactive plotting in tests",
)


def pytest_configure(config):
"""
Configures pytest based on command line options.
"""
if not config.option.plotting_on:
# We're not displaying plots so use a display-less backend
mpl.use("Agg")


@pytest.fixture
Expand Down Expand Up @@ -167,3 +183,51 @@ def disable_package_logger(monkeypatch):
was at the beginning of the test.
"""
monkeypatch.setattr(main, "PACKAGE_LOGGING", False)


@pytest.fixture(autouse=True)
def _plot_show_and_close(request):
"""Fixture to show and close plots

Notes
-----
Does not do anything if testclass marked with 'classplot'
"""
import matplotlib.pyplot as plt

cls = request.node.getparent(pytest.Class)

if cls and "classplot" in cls.keywords:
yield
else:
yield
clstitle = "" if cls is None else cls.name
for fig in list(map(plt.figure, plt.get_fignums())):
fig.suptitle(
f"{fig.get_suptitle()} {clstitle}::"
f"{request.node.getparent(pytest.Function).name}"
)
plt.show()
plt.close()


@pytest.fixture(scope="class", autouse=True)
def _plot_show_and_close_class(request):
"""Fixture to show and close plots for marked classes

Notes
-----
Only shows and closes figures on classes marked with 'classplot'
"""
import matplotlib.pyplot as plt

if "classplot" in request.keywords:
yield
clstitle = request.node.getparent(pytest.Class).name

for fig in list(map(plt.figure, plt.get_fignums())):
fig.suptitle(f"{fig.get_suptitle()} {clstitle}")
plt.show()
plt.close()
else:
yield
3,835 changes: 3,834 additions & 1 deletion tests/integration/data/SIG_TF.json

Large diffs are not rendered by default.

3,837 changes: 3,836 additions & 1 deletion tests/integration/data/large_tokamak_SIG_TF.json

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions tests/integration/data/mfile_to_csv_varlist.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"vars": [
"rmajor",
"p_plant_electric_net_mw",
"jwdgop"
]
}
{
"vars": ["rmajor", "p_plant_electric_net_mw", "jwdgop"]
}
Loading