Commit 8a54b4aa authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: rework fixPath test

parent a34bfb2d
......@@ -100,6 +100,11 @@ def tempdir(root=None, changeto=True):
shutil.rmtree(testdir)
def touch(path):
with open(path, 'wt') as f:
f.write(path)
def gen_test_data(num_vars,
num_subjs,
out_file,
......
......@@ -5,6 +5,9 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import site
import os
import shlex
import os.path as op
from unittest import mock
......@@ -12,26 +15,68 @@ from unittest import mock
import funpack.config as config
import funpack.custom as custom
from . import clear_plugins, tempdir
from . import clear_plugins, tempdir, touch
@clear_plugins
def test_parseArgs_fixPath():
def get_fmrib_config_dir():
for sitedir in site.getsitepackages():
fmribdir = op.join(sitedir, 'funpack', 'configs', 'fmrib')
if op.exists(fmribdir):
return fmribdir
custom.registerBuiltIns()
raise RuntimeError('Cannot locate FMRIB configuration directory')
fullpath = op.normpath(
op.join(op.dirname(__file__), '..',
'configs', 'fmrib', 'variables_clean.tsv'))
relpath = op.join('fmrib', 'variables_clean.tsv')
dotpath = 'fmrib.variables_clean'
argv = ['-vf', fullpath,
'-vf', relpath,
'-vf', dotpath, 'output', 'input']
# This function is essentially testing funpack.util.findConfigFile
@clear_plugins
def test_parseArgs_configFilePaths():
args = config.parseArgs(argv)[0]
custom.registerBuiltIns()
assert args.variable_file == [fullpath, fullpath, fullpath]
with tempdir() as td:
cfgdir = op.join(td, 'a')
os.makedirs(op.join(cfgdir, 'b'))
with mock.patch.dict(os.environ, FUNPACK_CONFIG_DIR=cfgdir):
cfgfile = op.join(cfgdir, 'b', 'myconfig.cfg')
varfile = op.join(cfgdir, 'b', 'myvars.tsv')
plgfile = op.join(cfgdir, 'b', 'myplugin.py')
touch(cfgfile)
touch(varfile)
touch(plgfile)
# full path
args = config.parseArgs(shlex.split(f'-cfg {cfgfile} out in'))[0]
assert args.config_file == [cfgfile]
# rel path
relp = op.join('a', 'b', 'myconfig.cfg')
args = config.parseArgs(shlex.split(f'-cfg {relp} out in'))[0]
assert args.config_file == [cfgfile]
# rel to cfgdir
relp = op.join('b', 'myconfig.cfg')
args = config.parseArgs(shlex.split(f'-cfg {relp} out in'))[0]
assert args.config_file == [cfgfile]
# dotted rel to cfgdir
args = config.parseArgs(shlex.split('-cfg b.myconfig out in'))[0]
assert args.config_file == [cfgfile]
argv = ['-vf', varfile,
'-vf', op.join('a', 'b', 'myvars.tsv'),
'-vf', op.join('b', 'myvars.tsv'),
'-vf', 'b.myvars',
'output', 'input']
args = config.parseArgs(argv)[0]
assert args.variable_file == [varfile, varfile, varfile, varfile]
argv = ['-p', plgfile,
'-p', op.join('a', 'b', 'myplugin.py'),
'-p', op.join('b', 'myplugin.py'),
'-p', 'b.myplugin',
'output', 'input']
args = config.parseArgs(argv)[0]
assert args.plugin_file == [plgfile, plgfile, plgfile, plgfile]
@clear_plugins
def test_num_jobs():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment