Skip to content

Commit

Permalink
Add test for modifying PATH when calling userscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-basevi committed Aug 22, 2024
1 parent 409c67f commit 0049fb0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/test_payu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import stat
import sys
from unittest.mock import patch

# Submodules
import payu
Expand Down Expand Up @@ -326,21 +327,23 @@ def test_run_userscript_python_script_with_shebang_header(tmp_path):
python_script = tmp_path / 'test_script_with_python_shebang.py'
with open(python_script, 'w') as f:
f.writelines([
'#!/usr/bin/env python\n'
'#!/usr/bin/env python3\n'
'import sys\n'
f"with open('{tmp_path}/output.txt', 'w') as f:\n",
" f.write('Test Python user script with python shebang header')"
" f.write(f'{sys.executable}')"
])

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

# Test run userscript
payu.fsops.run_script_command('test_script_with_python_shebang.py',
tmp_path)
with patch.dict(os.environ, {'PATH': '/mocked/path'}):
payu.fsops.run_script_command('test_script_with_python_shebang.py',
tmp_path)

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


def test_run_userscript_bash_script(tmp_path):
Expand Down

0 comments on commit 0049fb0

Please sign in to comment.