11""" Tests for the parrec2nii exe code
22"""
3- import imp
43from os .path import join , isfile , basename
54
65import numpy
98import nibabel
109from nibabel import parrec2nii_cmd as parrec2nii
1110
12- from mock import Mock , MagicMock
11+ from mock import Mock , MagicMock , patch
1312from nose .tools import assert_true
1413from numpy .testing import (assert_almost_equal , assert_array_equal )
1514
3029 [ 0. , 0. , 0. , 1. ]])
3130
3231
33- def teardown ():
34- # Reload tested module to clear run-time settings in tests
35- imp .reload (parrec2nii )
36-
37-
38- def test_parrec2nii_sets_qform_sform_code1 ():
39- # Unit test that ensures that set_qform() is called on the new header.
40- imp .reload (parrec2nii )
32+ @patch ('nibabel.parrec2nii_cmd.verbose' )
33+ @patch ('nibabel.parrec2nii_cmd.io_orientation' )
34+ @patch ('nibabel.parrec2nii_cmd.nifti1' )
35+ @patch ('nibabel.parrec2nii_cmd.pr' )
36+ def test_parrec2nii_sets_qform_sform_code1 (* args ):
37+ # Check that set_sform(), set_qform() are called on the new header.
4138 parrec2nii .verbose .switch = False
4239
43- parrec2nii .io_orientation = Mock ()
44- parrec2nii .io_orientation .return_value = [[0 , 1 ],[1 , 1 ],[2 , 1 ]] # LAS+
40+ parrec2nii .io_orientation .return_value = [[0 , 1 ],[1 , 1 ],[2 , 1 ]] # LAS+
4541
46- parrec2nii .nifti1 = Mock ()
4742 nimg = Mock ()
4843 nhdr = MagicMock ()
4944 nimg .header = nhdr
5045 parrec2nii .nifti1 .Nifti1Image .return_value = nimg
5146
52- parrec2nii .pr = Mock ()
5347 pr_img = Mock ()
5448 pr_hdr = Mock ()
5549 pr_hdr .get_data_scaling .return_value = (npa ([]), npa ([]))
@@ -73,11 +67,11 @@ def test_parrec2nii_sets_qform_sform_code1():
7367 nhdr .set_sform .assert_called_with (AN_OLD_AFFINE , code = 1 )
7468
7569
76- def test_parrec2nii_save_load_qform_code ():
70+ @patch ('nibabel.parrec2nii_cmd.verbose' )
71+ def test_parrec2nii_save_load_qform_code (* args ):
7772 # Tests that after parrec2nii saves file, it has the sform and qform 'code'
7873 # set to '1', which means 'scanner', so that other software, e.g. FSL picks
7974 # up the qform.
80- imp .reload (parrec2nii )
8175 parrec2nii .verbose .switch = False
8276
8377 opts = Mock ()
0 commit comments