enh: test also with dropping sessions
@@ -83,13 +83,15 @@ BOLD_PATH = 'ds054/sub-100185/func/sub-100185_task-machinegame_run-01_bold.nii.g
{"from": "orig", "to": "target", "suffix": "xfm"},
"sub-07/ses-preop/anat/sub-07_ses-preop_from-orig_to-target_mode-image_xfm.h5"),
])
+@pytest.mark.parametrize('dismiss_entities', [None, ("run", "session")])
def test_DerivativesDataSink_build_path(
tmp_path,
out_path_base,
source,
input_files,
entities,
- expectation
+ expectation,
+ dismiss_entities,
):
"""Check a few common derivatives generated by NiPreps."""
ds_inputs = []
@@ -113,6 +115,7 @@ def test_DerivativesDataSink_build_path(
base_directory=str(tmp_path),
source_file=source,
out_path_base=out_path_base,
+ dismiss_entities=dismiss_entities,
**entities,
)
@@ -121,31 +124,38 @@ def test_DerivativesDataSink_build_path(
dds.run()
return
- dds = dds.run()
- base = out_path_base or "niworkflows"
+ output = dds.run().outputs.out_file
if isinstance(expectation, str):
- assert Path(dds.outputs.out_file).relative_to(tmp_path) \
- == Path(base) / expectation
- else:
- for out, exp in zip(dds.outputs.out_file, expectation):
+ expectation = [expectation]
+ output = [output]
+
+ if dismiss_entities:
+ if "run" in dismiss_entities:
+ expectation = [e.replace("_run-1", "") for e in expectation]
+
+ if "session" in dismiss_entities:
+ expectation = [e.replace("_ses-preop", "").replace("ses-preop/", "")
+ for e in expectation]
+
+ base = out_path_base or "niworkflows"
+ for out, exp in zip(output, expectation):
assert Path(out).relative_to(tmp_path) == Path(base) / exp
os.chdir(str(tmp_path)) # Exercise without setting base_directory
dds = bintfs.DerivativesDataSink(
in_file=ds_inputs,
- dismiss_entities="run",
+ dismiss_entities=dismiss_entities,
source_file=source,
out_path_base=out_path_base,
**entities,
- ).run()
+ )
- if isinstance(expectation, str):
- assert Path(dds.outputs.out_file).relative_to(tmp_path) \
- == Path(base) / expectation.replace("_run-1", "")
- else:
- for out, exp in zip(dds.outputs.out_file, expectation):
- assert Path(out).relative_to(tmp_path) \
- == Path(base) / exp.replace("_run-1", "")
+ output = dds.run().outputs.out_file
+ if isinstance(output, str):
+ output = [output]
+
+ for out, exp in zip(output, expectation):
+ assert Path(out).relative_to(tmp_path) == Path(base) / exp
@pytest.mark.parametrize('space, size, units, xcodes, zipped, fixed, data_dtype', [
