forked from noaa-ocs-modeling/ondemand-storm-workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from oceanmodeling/feature/enforce_input_version
Check and enforce input version
- Loading branch information
Showing
7 changed files
with
261 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '**.py' | ||
- '.github/workflows/tests.yml' | ||
- 'pyproject.toml' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: test | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
python-version: [ '3.9', '3.10', '3.11' ] | ||
steps: | ||
- name: clone repository | ||
uses: actions/checkout@v4 | ||
- name: conda virtual environment | ||
uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
init-shell: bash | ||
environment-file: environment.yml | ||
- name: install the package | ||
run: pip install ".[dev]" | ||
shell: micromamba-shell {0} | ||
- name: run tests | ||
run: pytest | ||
shell: micromamba-shell {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
input_version: 0.0.1 | ||
|
||
storm: "florence" | ||
year: 2018 | ||
suffix: "" | ||
subset_mesh: 1 | ||
hr_prelandfall: -1 | ||
past_forecast: 1 | ||
hydrology: 0 | ||
use_wwm: 0 | ||
pahm_model: "gahm" | ||
num_perturb: 2 | ||
sample_rule: "korobov" | ||
spinup_exec: "pschism_PAHM_TVD-VL" | ||
hotstart_exec: "pschism_PAHM_TVD-VL" | ||
|
||
hpc_solver_nnodes: 3 | ||
hpc_solver_ntasks: 108 | ||
hpc_account: "" | ||
hpc_partition: "" | ||
|
||
RUN_OUT: "" | ||
L_NWM_DATASET: "" | ||
L_TPXO_DATASET: "" | ||
L_LEADTIMES_DATASET: "" | ||
L_TRACK_DIR: "" | ||
L_DEM_HI: "" | ||
L_DEM_LO: "" | ||
L_MESH_HI: "" | ||
L_MESH_LO: "" | ||
L_SHP_DIR: "" | ||
|
||
TMPDIR: "/tmp" | ||
PATH_APPEND: "" | ||
|
||
L_SOLVE_MODULES: | ||
- "intel/2022.1.2" | ||
- "impi/2022.1.2" | ||
- "netcdf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
input_version: 0.0.2 | ||
|
||
storm: "florence" | ||
year: 2018 | ||
suffix: "" | ||
subset_mesh: 1 | ||
hr_prelandfall: -1 | ||
past_forecast: 1 | ||
hydrology: 0 | ||
use_wwm: 0 | ||
pahm_model: "gahm" | ||
num_perturb: 2 | ||
sample_rule: "korobov" | ||
spinup_exec: "pschism_PAHM_TVD-VL" | ||
hotstart_exec: "pschism_PAHM_TVD-VL" | ||
perturb_vars: | ||
- 'cross_track' | ||
- 'along_track' | ||
# - 'radius_of_maximum_winds' | ||
- 'radius_of_maximum_winds_persistent' | ||
- 'max_sustained_wind_speed' | ||
|
||
hpc_solver_nnodes: 3 | ||
hpc_solver_ntasks: 108 | ||
hpc_account: "" | ||
hpc_partition: "" | ||
|
||
RUN_OUT: "" | ||
L_NWM_DATASET: "" | ||
L_TPXO_DATASET: "" | ||
L_LEADTIMES_DATASET: "" | ||
L_TRACK_DIR: "" | ||
L_DEM_HI: "" | ||
L_DEM_LO: "" | ||
L_MESH_HI: "" | ||
L_MESH_LO: "" | ||
L_SHP_DIR: "" | ||
|
||
TMPDIR: "/tmp" | ||
PATH_APPEND: "" | ||
|
||
L_SOLVE_MODULES: | ||
- "intel/2022.1.2" | ||
- "impi/2022.1.2" | ||
- "netcdf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from copy import deepcopy | ||
from importlib.resources import files | ||
|
||
import pytest | ||
import yaml | ||
from packaging.version import Version | ||
from yaml import Loader, Dumper | ||
|
||
from stormworkflow.main import handle_input_version, CUR_INPUT_VER | ||
|
||
|
||
refs = files('tests.data.refs') | ||
input_v0_0_1 = refs.joinpath('input_v0.0.1.yaml') | ||
input_v0_0_2 = refs.joinpath('input_v0.0.2.yaml') | ||
|
||
|
||
def read_conf(infile): | ||
with open(infile, 'r') as yfile: | ||
conf = yaml.load(yfile, Loader=Loader) | ||
return conf | ||
|
||
|
||
@pytest.fixture | ||
def conf_v0_0_1(): | ||
return read_conf(input_v0_0_1) | ||
|
||
|
||
@pytest.fixture | ||
def conf_v0_0_2(): | ||
return read_conf(input_v0_0_2) | ||
|
||
|
||
@pytest.fixture | ||
def conf_latest(conf_v0_0_2): | ||
return conf_v0_0_2 | ||
|
||
|
||
def test_no_version_specified(conf_latest): | ||
conf_latest.pop('input_version') | ||
with pytest.warns(UserWarning): | ||
handle_input_version(conf_latest) | ||
|
||
assert conf_latest['input_version'] == str(CUR_INPUT_VER) | ||
|
||
|
||
def test_invalid_version_specified(conf_latest): | ||
|
||
invalid_1 = deepcopy(conf_latest) | ||
invalid_1['input_version'] = ( | ||
f'{CUR_INPUT_VER.major}.{CUR_INPUT_VER.minor}.{CUR_INPUT_VER.micro + 1}' | ||
) | ||
with pytest.raises(ValueError) as e: | ||
handle_input_version(invalid_1) | ||
|
||
assert "max" in str(e.value).lower() | ||
|
||
|
||
invalid_2 = deepcopy(conf_latest) | ||
invalid_2['input_version'] = 'a.b.c' | ||
with pytest.raises(ValueError) as e: | ||
handle_input_version(invalid_2) | ||
assert "invalid version" in str(e.value).lower() | ||
|
||
|
||
def test_v0_0_1_to_v0_0_2(conf_v0_0_1, conf_v0_0_2): | ||
handle_input_version(conf_v0_0_1) | ||
assert conf_v0_0_2 == conf_v0_0_1 |