def _execute_spm_config_test(defaults, explicitly_set, spm_root): """execute tests prepared by test_spm_config.""" defaults = dict(defaults) explicitly_set = dict(explicitly_set) # at the beginning all paths point to bad locations, # configuration should fail spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (spm_dir is None) _fix_spm_testing_default(defaults, 'matlab_exec') # path to Matlab was fixed but still no path to SPM home dir, # configuration should fail. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (spm_dir is None) _fix_spm_testing_default(defaults, 'spm_dir_template') # path to Matlab is good, path to spm13 is valid but this installation # is broken (missing tpm dir), so spm12 should be selected. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (os.path.samefile( spm_dir, os.path.join(spm_root, 'spm12/spm12/spm12_mcr/spm12/'))) _break_spm_testing_default(defaults, 'spm_dir_template') _fix_spm_testing_default(defaults, 'spm_mcr_template') # path to Matlab is bad but paths to SPM MCRs are good, # paths to SPM home dirs are bad but can be inferred from # SPM MCR location; configuration should succeed and select # spm12 (spm13 is broken). spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (os.path.samefile( spm_dir, os.path.join(spm_root, 'spm12/spm12/spm12_mcr/spm12/'))) _logger.debug('setting TEST_SPM_MCR env variable') os.environ['TEST_SPM_MCR'] = os.path.join(spm_root, 'spm7/spm7.sh/') # environment variables have priority over defaults, so spm7 # should be preferred. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (os.path.samefile( spm_dir, os.path.join(spm_root, 'spm7/spm7/spm7_mcr/spm7/'))) _fix_spm_testing_explicitly_set_location(explicitly_set, 'config_spm_mcr') # path to spm specified in config file was fixed and points to # spm8, spm8 should be chosen. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (os.path.samefile( spm_dir, os.path.join(spm_root, 'spm8/spm8/spm8_mcr/spm8/'))) _fix_spm_testing_explicitly_set_location(explicitly_set, 'cli_spm_mcr') # path to spm specified in command line was fixed and points to spm7, # since cli has priority over config file, spm7 should be chosen. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert (os.path.samefile( spm_dir, os.path.join(spm_root, 'spm7/spm7/spm7_mcr/spm7/'))) _logger.debug('setting "prefer_matlab"') _fix_spm_testing_default(defaults, 'spm_dir_template') # paths to SPM homes were fixed; since we prefer Matlab the version # of the preferred MCR has no importance and is ignored; the highest # valid install (spm12) should be chosen. spm_dir = _configure_spm(defaults=defaults, prefer_matlab=True, **explicitly_set) assert (os.path.samefile( spm_dir, os.path.join(spm_root, 'spm12/spm12/spm12_mcr/spm12/'))) _logger.info('SPM config test succeeded')
def _execute_spm_config_test(defaults, explicitly_set, spm_root): """execute tests prepared by test_spm_config.""" defaults = dict(defaults) explicitly_set = dict(explicitly_set) # at the beginning all paths point to bad locations, # configuration should fail spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(spm_dir is None) _fix_spm_testing_default(defaults, 'matlab_exec') # path to Matlab was fixed but still no path to SPM home dir, # configuration should fail. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(spm_dir is None) _fix_spm_testing_default(defaults, 'spm_dir_template') # path to Matlab is good, path to spm13 is valid but this installation # is broken (missing tpm dir), so spm12 should be selected. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(os.path.samefile( spm_dir, os.path.join(spm_root, 'spm12/spm12/spm12_mcr/spm12/'))) _break_spm_testing_default(defaults, 'spm_dir_template') _fix_spm_testing_default(defaults, 'spm_mcr_template') # path to Matlab is bad but paths to SPM MCRs are good, # paths to SPM home dirs are bad but can be inferred from # SPM MCR location; configuration should succeed and select # spm12 (spm13 is broken). spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(os.path.samefile( spm_dir, os.path.join(spm_root, 'spm12/spm12/spm12_mcr/spm12/'))) _logger.debug('setting TEST_SPM_MCR env variable') os.environ['TEST_SPM_MCR'] = os.path.join(spm_root, 'spm7/spm7.sh/') # environment variables have priority over defaults, so spm7 # should be preferred. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(os.path.samefile( spm_dir, os.path.join(spm_root, 'spm7/spm7/spm7_mcr/spm7/'))) _fix_spm_testing_explicitly_set_location(explicitly_set, 'config_spm_mcr') # path to spm specified in config file was fixed and points to # spm8, spm8 should be chosen. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(os.path.samefile( spm_dir, os.path.join(spm_root, 'spm8/spm8/spm8_mcr/spm8/'))) _fix_spm_testing_explicitly_set_location(explicitly_set, 'cli_spm_mcr') # path to spm specified in command line was fixed and points to spm7, # since cli has priority over config file, spm7 should be chosen. spm_dir = _configure_spm(defaults=defaults, **explicitly_set) assert(os.path.samefile( spm_dir, os.path.join(spm_root, 'spm7/spm7/spm7_mcr/spm7/'))) _logger.debug('setting "prefer_matlab"') _fix_spm_testing_default(defaults, 'spm_dir_template') # paths to SPM homes were fixed; since we prefer Matlab the version # of the preferred MCR has no importance and is ignored; the highest # valid install (spm12) should be chosen. spm_dir = _configure_spm(defaults=defaults, prefer_matlab=True, **explicitly_set) assert(os.path.samefile( spm_dir, os.path.join(spm_root, 'spm12/spm12/spm12_mcr/spm12/'))) _logger.info('SPM config test succeeded')
def _fix_spm_testing_explicitly_set_location(locations_dict, key_to_fix): _logger.debug('SPM config testing: fixing {}'.format(key_to_fix)) locations_dict[key_to_fix] = locations_dict[ key_to_fix].replace('.BAD_LOC', '')
def _break_spm_testing_default(defaults_dict, key_to_fix): _logger.debug('SPM config testing: breaking {}'.format(key_to_fix)) defaults_dict[key_to_fix] = ['.'.join([s, 'BAD_LOC']) for s in defaults_dict[key_to_fix]]
def _fix_spm_testing_default(defaults_dict, key_to_fix): _logger.debug('SPM config testing: fixing {}'.format(key_to_fix)) defaults_dict[key_to_fix] = [ s.replace('.BAD_LOC', '') for s in defaults_dict[key_to_fix]]
def _fix_spm_testing_explicitly_set_location(locations_dict, key_to_fix): _logger.debug('SPM config testing: fixing {}'.format(key_to_fix)) locations_dict[key_to_fix] = locations_dict[key_to_fix].replace( '.BAD_LOC', '')
def _break_spm_testing_default(defaults_dict, key_to_fix): _logger.debug('SPM config testing: breaking {}'.format(key_to_fix)) defaults_dict[key_to_fix] = [ '.'.join([s, 'BAD_LOC']) for s in defaults_dict[key_to_fix] ]
def _fix_spm_testing_default(defaults_dict, key_to_fix): _logger.debug('SPM config testing: fixing {}'.format(key_to_fix)) defaults_dict[key_to_fix] = [ s.replace('.BAD_LOC', '') for s in defaults_dict[key_to_fix] ]