Skip to content

Commit

Permalink
Merge pull request #16 from tclose/unitests
Browse files Browse the repository at this point in the history
Added NIfTI unittest
  • Loading branch information
tclose authored Sep 28, 2022
2 parents b2f1830 + 69a3f38 commit ff28f7b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ jobs:
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- name: Install Minconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-activate-base: true
activate-environment: ""
- name: Install MRtrix via Conda
run: |
conda install -c mrtrix3 mrtrix3
mrconvert --version
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
Expand Down
22 changes: 22 additions & 0 deletions conftest.py
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
37 changes: 31 additions & 6 deletions pydra/tasks/mrtrix3/tests/test_utils.py
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()
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers =
[options]
python_requires = >=3.7
install_requires =
pydra >= 0.6.2
pydra >= 0.19
packages = find_namespace:

[options.packages.find]
Expand All @@ -44,7 +44,7 @@ test =
pytest-env
pytest-xdist
pytest-rerunfailures
medimages4tests
medimages4tests >= 0.2
codecov
tests =
%(test)s
Expand Down

0 comments on commit ff28f7b

Please sign in to comment.