|
5 | 5 | from pathlib import Path |
6 | 6 | import shutil |
7 | 7 | import sys |
| 8 | +from unittest.mock import patch |
8 | 9 |
|
9 | 10 | import pdb |
10 | 11 | import pytest |
@@ -236,6 +237,47 @@ def test_run(): |
236 | 237 | assert(args.remaining[-1].endswith(payu_cmd)) |
237 | 238 |
|
238 | 239 |
|
| 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 | + |
239 | 281 | def test_tenacity(): |
240 | 282 |
|
241 | 283 | # This should fail and do nothing |
|
0 commit comments