Skip to content

Commit b1bedc5

Browse files
authored
Fix parsing job ID in payu run submission stdout (#186)
1 parent 74de9cd commit b1bedc5

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/model_config_tests/exp_test_helper.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,15 @@ def setup_exp(
345345

346346

347347
def parse_run_id(stdout: str) -> str:
348-
"""Parses the run ID from the subprocess stdout that submits payu run.
349-
The run ID is the first line of the stdout."""
350-
run_id = stdout.splitlines()[0]
351-
return run_id
348+
"""Parses the Gadi PBS run ID from the subprocess stdout that submits payu
349+
run"""
350+
ids = parse_gadi_pbs_ids(stdout)
351+
if len(ids) != 1:
352+
raise RuntimeError(
353+
"Expected 1 job ID in payu run submission, "
354+
f"but found {len(ids)}. IDs: {ids}"
355+
)
356+
return ids[0]
352357

353358

354359
def parse_gadi_pbs_ids(stdout: str) -> list[str]:

tests/test_exp_test_helper.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,29 @@ def test_experiment_submit_payu_run_error(mock_run, exp):
186186
assert exp.run_id is None
187187

188188

189-
TEST_RUN_STDOUT = """137650670.gadi-pbs
190-
Loading input manifest: manifests/input.yaml
191-
Loading restart manifest: manifests/restart.yaml
192-
Loading exe manifest: manifests/exe.yaml
193-
payu: Found modules in /opt/Modules/v4.3.0
194-
qsub -q express -- /path/to/env/bin/python /path/to/env/bin/payu-run
195-
"""
189+
@pytest.mark.parametrize(
190+
"example_stdout",
191+
[
192+
"137650670.gadi-pbs\ngadi-pbs ID output is first line\n",
193+
"gadi-pbs ID\nIs the last line\n137650670.gadi-pbs\n",
194+
],
195+
)
196+
def test_parse_run_id(example_stdout):
197+
run_id = parse_run_id(example_stdout)
198+
assert run_id == "137650670.gadi-pbs"
196199

197200

198-
def test_parse_run_id():
199-
run_id = parse_run_id(TEST_RUN_STDOUT)
200-
assert run_id == "137650670.gadi-pbs"
201+
@pytest.mark.parametrize(
202+
"example_stdout",
203+
[
204+
"No job ID here\nJust some output\n",
205+
"Multiple IDs\n12345.gadi-pbs\n67890.gadi-pbs\n",
206+
],
207+
)
208+
def test_parse_run_id_parsing_error(example_stdout):
209+
error_msg = "Expected 1 job ID in payu run submission.*"
210+
with pytest.raises(RuntimeError, match=error_msg):
211+
parse_run_id(example_stdout)
201212

202213

203214
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)