Skip to content

Commit 0049fb0

Browse files
committed
Add test for modifying PATH when calling userscripts
1 parent 409c67f commit 0049fb0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/test_payu.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77
import stat
88
import sys
9+
from unittest.mock import patch
910

1011
# Submodules
1112
import payu
@@ -326,21 +327,23 @@ def test_run_userscript_python_script_with_shebang_header(tmp_path):
326327
python_script = tmp_path / 'test_script_with_python_shebang.py'
327328
with open(python_script, 'w') as f:
328329
f.writelines([
329-
'#!/usr/bin/env python\n'
330+
'#!/usr/bin/env python3\n'
331+
'import sys\n'
330332
f"with open('{tmp_path}/output.txt', 'w') as f:\n",
331-
" f.write('Test Python user script with python shebang header')"
333+
" f.write(f'{sys.executable}')"
332334
])
333335

334336
# Make file executable
335337
os.chmod(python_script, 0o775)
336338

337339
# Test run userscript
338-
payu.fsops.run_script_command('test_script_with_python_shebang.py',
339-
tmp_path)
340+
with patch.dict(os.environ, {'PATH': '/mocked/path'}):
341+
payu.fsops.run_script_command('test_script_with_python_shebang.py',
342+
tmp_path)
340343

341-
# Check script output
344+
# Check script is run with same python executable as caller
342345
with open((tmp_path / 'output.txt'), 'r') as f:
343-
assert f.read() == "Test Python user script with python shebang header"
346+
assert f.read() == sys.executable
344347

345348

346349
def test_run_userscript_bash_script(tmp_path):

0 commit comments

Comments
 (0)