Skip to content
Snippets Groups Projects
Commit a2265ea3 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

TEST: unit test for creating *_gui wrapper scripts

parent 730c3124
No related branches found
No related tags found
1 merge request!20Rf/gui wrappers
Pipeline #10287 passed
...@@ -11,6 +11,7 @@ import sys ...@@ -11,6 +11,7 @@ import sys
import os.path as op import os.path as op
import subprocess as sp import subprocess as sp
import textwrap as tw import textwrap as tw
import itertools as it
import os import os
import shlex import shlex
import shutil import shutil
...@@ -64,6 +65,22 @@ def touch(path): ...@@ -64,6 +65,22 @@ def touch(path):
f.write('.') f.write('.')
def get_called_command(filename):
"""Returns the command that is being called by the given wrapper script.
"""
with open(filename, 'rt') as f:
line = f.readlines()[1]
tokens = line.split()
cmd = op.basename(tokens[0])
if cmd in ('python', 'pythonw'):
cmd = tokens[2]
return cmd
def test_env_vars_not_set(): def test_env_vars_not_set():
"""Test that wrapper scripts are not created if the """Test that wrapper scripts are not created if the
FSL_CREATE_WRAPPER_SCRIPTS, FSLDIR, or PREFIX environment variables FSL_CREATE_WRAPPER_SCRIPTS, FSLDIR, or PREFIX environment variables
...@@ -219,6 +236,46 @@ def test_create_remove_wrappers(): ...@@ -219,6 +236,46 @@ def test_create_remove_wrappers():
assert not op.exists(op.join(wrapperdir, 'test_script2')) assert not op.exists(op.join(wrapperdir, 'test_script2'))
def test_create_gui_wrappers():
"""Tests creation of wrappers for FSL GUI commands, which are called
"<Command>_gui" on macOS, and "<Command>" on linux, where "<command>"
(note the case) may also exist. Post-link scripts should only pass the
"<Command>_gui" variant.
"""
# Test outcome differs for different platforms.
# Keys are passed to createFSLWrapper, values are
# wrappers that should be created
if sys.platform == 'darwin':
scripts = {'script' : 'script',
'Script_gui' : 'Script_gui'}
# linux
else:
scripts = {'script' : 'script',
'Script_gui' : 'Script'}
with temp_fsldir() as (fsldir, wrapperdir):
for target in scripts.values():
touch(op.join(fsldir, 'bin', target))
for wrappers in it.permutations(scripts.keys()):
args = ' '.join(wrappers)
run(f'{CREATE_WRAPPER} {args}')
for arg in wrappers:
target = scripts[arg]
wrapper = op.join(wrapperdir, target)
assert op.exists(wrapper)
assert get_called_command(wrapper) == scripts[arg]
run(f'{REMOVE_WRAPPER} {args}')
for arg in wrappers:
target = scripts[arg]
wrapper = op.join(wrapperdir, target)
assert not op.exists(wrapper)
if __name__ == '__main__': if __name__ == '__main__':
# base dir can be speecified on command line # base dir can be speecified on command line
if len(sys.argv) > 1: if len(sys.argv) > 1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment