-
Notifications
You must be signed in to change notification settings - Fork 532
tst: use pytest fixture #3059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
tst: use pytest fixture #3059
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,42 +14,45 @@ | |||||||||
DICOM_DIR = 'http://datasets-tests.datalad.org/dicoms/dcm2niix-tests' | ||||||||||
|
||||||||||
|
||||||||||
def fetch_data(datadir, dicoms): | ||||||||||
"""Fetches some test DICOMs using datalad""" | ||||||||||
api.install(path=datadir, source=DICOM_DIR) | ||||||||||
data = os.path.join(datadir, dicoms) | ||||||||||
api.get(path=data) | ||||||||||
return data | ||||||||||
@pytest.fixture | ||||||||||
def fetch_data(): | ||||||||||
def _fetch_data(datadir, dicoms): | ||||||||||
try: | ||||||||||
"""Fetches some test DICOMs using datalad""" | ||||||||||
api.install(path=datadir, source=DICOM_DIR) | ||||||||||
data = os.path.join(datadir, dicoms) | ||||||||||
api.get(path=data) | ||||||||||
except IncompleteResultsError as exc: | ||||||||||
pytest.skip("Failed to fetch test data: %s" % str(exc)) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
return data | ||||||||||
return _fetch_data | ||||||||||
|
||||||||||
@pytest.mark.skipif(no_datalad, reason="Datalad required") | ||||||||||
@pytest.mark.skipif(no_dcm2niix, reason="Dcm2niix required") | ||||||||||
def test_dcm2niix_dwi(tmpdir): | ||||||||||
def test_dcm2niix_dti(fetch_data, tmpdir): | ||||||||||
tmpdir.chdir() | ||||||||||
datadir = tmpdir.mkdir('data').strpath | ||||||||||
try: | ||||||||||
dicoms = fetch_data(datadir, 'Siemens_Sag_DTI_20160825_145811') | ||||||||||
except IncompleteResultsError as exc: | ||||||||||
pytest.skip("Failed to fetch test data: %s" % str(exc)) | ||||||||||
dicoms = fetch_data(datadir, 'Siemens_Sag_DTI_20160825_145811') | ||||||||||
|
||||||||||
def assert_dwi(eg): | ||||||||||
def assert_dti(res): | ||||||||||
"Some assertions we will make" | ||||||||||
assert eg.outputs.converted_files | ||||||||||
assert eg.outputs.bvals | ||||||||||
assert eg.outputs.bvecs | ||||||||||
outputs = [y for x,y in eg.outputs.get().items()] | ||||||||||
if eg.inputs.get('bids_format'): | ||||||||||
assert res.outputs.converted_files | ||||||||||
assert res.outputs.bvals | ||||||||||
assert res.outputs.bvecs | ||||||||||
outputs = [y for x,y in res.outputs.get().items()] | ||||||||||
if res.inputs.get('bids_format'): | ||||||||||
# ensure all outputs are of equal lengths | ||||||||||
assert len(set(map(len, outputs))) == 1 | ||||||||||
else: | ||||||||||
assert not eg.outputs.bids | ||||||||||
assert not res.outputs.bids | ||||||||||
|
||||||||||
dcm = Dcm2niix() | ||||||||||
dcm.inputs.source_dir = dicoms | ||||||||||
dcm.inputs.out_filename = '%u%z' | ||||||||||
assert_dwi(dcm.run()) | ||||||||||
assert_dti(dcm.run()) | ||||||||||
|
||||||||||
# now run specifying output directory and removing BIDS option | ||||||||||
outdir = tmpdir.mkdir('conversion').strpath | ||||||||||
dcm.inputs.output_dir = outdir | ||||||||||
dcm.inputs.bids_format = False | ||||||||||
assert_dwi(dcm.run()) | ||||||||||
assert_dti(dcm.run()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.