nipreps / smriprep

Structural MRI PREProcessing (sMRIPrep) workflows for NIPreps (NeuroImaging PREProcessing tools)

Home Page:https://nipreps.github.io/smriprep

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TemplateFlow interface doctests fail

effigies opened this issue · comments

Describe the bug
Test failure.

Exact command line executed

pytest --doctest-modules smriprep

Result:

=============================================== FAILURES ================================================
_____________________ [doctest] smriprep.interfaces.templateflow.TemplateFlowSelect _____________________
082     >>> select = TemplateFlowSelect()
083     >>> select.inputs.template = 'MNIPediatricAsym:cohort-2'
084     >>> select.inputs.template_spec = {'cohort': 5, 'resolution': 1}
085     >>> result = select.run()
086     >>> result.outputs.t1w_file  # doctest: +ELLIPSIS
087     '.../tpl-MNIPediatricAsym_cohort-5_res-1_T1w.nii.gz'
088 
089     >>> select = TemplateFlowSelect()
090     >>> select.inputs.template = 'UNCInfant:cohort-1'
091     >>> result = select.run()
UNEXPECTED EXCEPTION: FileNotFoundError("No such file or directory '[]' for output 't1w_file' of a TemplateFlowSelect interface")
Traceback (most recent call last):
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 129, in validate
    value = Path(value)  # Use pathlib's validation
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/pathlib.py", line 1072, in __new__
    self = cls._from_parts(args, init=False)
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/pathlib.py", line 697, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/pathlib.py", line 681, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 530, in aggregate_outputs
    setattr(outputs, key, val)
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 330, in validate
    value = super(File, self).validate(objekt, name, value, return_pathlike=True)
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/nipype/interfaces/base/traits_extension.py", line 131, in validate
    self.error(objekt, name, str(value))
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/traits/base_trait_handler.py", line 74, in error
    raise TraitError(
traits.trait_errors.TraitError: The 't1w_file' trait of a _TemplateFlowSelectOutputSpec instance must be a pathlike object or string representing an existing file, but a value of '[]' <class 'str'> was specified.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/doctest.py", line 1336, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest smriprep.interfaces.templateflow.TemplateFlowSelect[22]>", line 1, in <module>
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 430, in run
    outputs = self.aggregate_outputs(runtime)
  File "/home/chris/miniconda3/envs/smriprep-dev/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 537, in aggregate_outputs
    raise FileNotFoundError(msg)
FileNotFoundError: No such file or directory '[]' for output 't1w_file' of a TemplateFlowSelect interface
/home/chris/Projects/nipreps/smriprep/smriprep/interfaces/templateflow.py:91: UnexpectedException

The doctest was introduced in db0396c, part of #257.

Running PDB, we can see that these conflict:

template_spec = traits.DictStrAny(
{"atlas": None, "cohort": None}, usedefault=True, desc="Template specifications"
)

if len(name) > 1:
specs.update(
{
k: v
for modifier in name[1].split(":")
for k, v in [tuple(modifier.split("-"))]
if k not in specs
}
)
self._results["t1w_file"] = tf.get(name[0], desc=None, suffix="T1w", **specs)

Because cohort is in the default spec, it's not being updated from the string. Removing L114 causes this one to fail, as 2 overrides 5:

>>> select.inputs.template = 'MNIPediatricAsym:cohort-2'
>>> select.inputs.template_spec = {'cohort': 5, 'resolution': 1}
>>> result = select.run()
>>> result.outputs.t1w_file # doctest: +ELLIPSIS
'.../tpl-MNIPediatricAsym_cohort-5_res-1_T1w.nii.gz'

I don't know what the correct fix is.

Installation type (please complete the following information):

  • "Bare-metal"

This is still open, but currently managed by skipping the doctest.