generated from nipype/pydra-tasks-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from tclose/unitests
Added NIfTI unittest
- Loading branch information
Showing
4 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def work_dir(): | ||
return Path(tempfile.mkdtemp()) | ||
|
||
|
||
# For debugging in IDE's don't catch raised exceptions and let the IDE | ||
# break at it | ||
if os.getenv("_PYTEST_RAISE", "0") != "0": | ||
|
||
@pytest.hookimpl(tryfirst=True) | ||
def pytest_exception_interact(call): | ||
raise call.excinfo.value | ||
|
||
@pytest.hookimpl(tryfirst=True) | ||
def pytest_internalerror(excinfo): | ||
raise excinfo.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
from pathlib import Path | ||
import pytest | ||
from pydra.tasks.mrtrix3.utils import MRConvert | ||
from medimages4tests.dicom.mri.dwi.siemens.skyra.syngo_d13c import sample_image | ||
from medimages4tests.dicom.mri.dwi.siemens.skyra.syngo_d13c import ( | ||
sample_image as sample_dwi_dicom, | ||
) | ||
from medimages4tests.nifti import sample_image as sample_nifti | ||
|
||
|
||
@pytest.fixture | ||
def dicom_dataset(): | ||
return sample_image() | ||
def dwi_dicom_dataset(): | ||
return sample_dwi_dicom() | ||
|
||
|
||
def test_mrconvert(dicom_dataset): | ||
@pytest.fixture | ||
def nifti_dataset(work_dir): | ||
return sample_nifti(work_dir / "nifti", compressed=True) | ||
|
||
|
||
def test_mrconvert_default_out_file(nifti_dataset): | ||
|
||
task = MRConvert(in_file=nifti_dataset, axes=[0, 1, 2, -1]) | ||
|
||
result = task() | ||
|
||
assert Path(result.output.out_file).exists() | ||
|
||
|
||
@pytest.mark.xfail( | ||
reason=( | ||
"Cannot pass input to input field with 'output_file_template' " | ||
"https://github.com/nipype/pydra/pull/585 (or equivalent) is merged " | ||
"into main branch" | ||
) | ||
) | ||
def test_mrconvert_explicit_out_file(dwi_dicom_dataset): | ||
|
||
task = MRConvert(in_file=dicom_dataset, out_file="test.nii.gz") | ||
task = MRConvert(in_file=dwi_dicom_dataset, out_file="test.nii.gz") | ||
|
||
result = task() | ||
|
||
assert result.output.out_file.exists() | ||
assert Path(result.output.out_file).exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters