diff --git a/tests/test_create_remove_wrapper.py b/tests/test_create_remove_wrapper.py index 09ae0fc11a94d63f92974f70bc7bb42b2982ecd4..6170f778c8ce6163d602ce7970093c600437398d 100755 --- a/tests/test_create_remove_wrapper.py +++ b/tests/test_create_remove_wrapper.py @@ -11,6 +11,7 @@ import sys import os.path as op import subprocess as sp import textwrap as tw +import itertools as it import os import shlex import shutil @@ -64,6 +65,22 @@ def touch(path): 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(): """Test that wrapper scripts are not created if the FSL_CREATE_WRAPPER_SCRIPTS, FSLDIR, or PREFIX environment variables @@ -219,6 +236,46 @@ def test_create_remove_wrappers(): 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__': # base dir can be speecified on command line if len(sys.argv) > 1: