Skip to content

Commit 13f30fe

Browse files
committed
Add test for setting launcher script in qsub command
1 parent 8bc93d2 commit 13f30fe

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎test/test_pbs.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
import shutil
77
import sys
8+
from unittest.mock import patch
89

910
import pdb
1011
import pytest
@@ -236,6 +237,47 @@ def test_run():
236237
assert(args.remaining[-1].endswith(payu_cmd))
237238

238239

240+
@patch("payu.schedulers.pbs.pbs_env_init", return_value=True)
241+
@patch("payu.schedulers.pbs.check_exe_path", side_effect=lambda x, y: y)
242+
@pytest.mark.parametrize(
243+
"env_exists,file_exists,file_exe,expected_cmd",
244+
[
245+
# Test backwards compatibility with no launcher script
246+
(False, False, False, "/path/to/python payu-run"),
247+
# With only launcher script env set
248+
(True, False, False, "/path/to/python payu-run"),
249+
# With launch script env and file exists
250+
(True, True, False, "/path/to/python payu-run"),
251+
# With launch script env, file exists, and file is executable
252+
(True, True, True, "{tmp_path}/launcher.sh /path/to/python payu-run")
253+
],
254+
)
255+
def test_submit_launcher_script_setting(
256+
mock_pbs_env_init, mock_check_exe_path,
257+
env_exists, file_exists, file_exe, expected_cmd, tmp_path, monkeypatch
258+
):
259+
config = {
260+
"control_path": "/path/to/experiment"
261+
}
262+
263+
# Setup based on test parameters
264+
if env_exists:
265+
monkeypatch.setenv("ENV_LAUNCHER_SCRIPT_PATH",
266+
f"{tmp_path}/launcher.sh")
267+
if file_exists:
268+
launcher_script_path = tmp_path / "launcher.sh"
269+
launcher_script_path.write_text("#!/bin/bash\necho 'Running...'\n")
270+
if file_exe:
271+
launcher_script_path.chmod(0o755)
272+
273+
# Generate the qsub command
274+
pbs_cmd = pbs.PBS().submit("payu-run", config,
275+
python_exe="/path/to/python")
276+
277+
_, cmd = pbs_cmd.split("--")
278+
assert cmd.strip() == expected_cmd.format(tmp_path=tmp_path)
279+
280+
239281
def test_tenacity():
240282

241283
# This should fail and do nothing

0 commit comments

Comments
 (0)