Skip to content

Commit 7b719c4

Browse files
author
CindeeM
committed
RF - removed parametric tests from test_ecat
1 parent f6de26c commit 7b719c4

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

nibabel/tests/test_ecat.py

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,73 @@
1010
from StringIO import StringIO
1111
import numpy as np
1212

13-
from ..testing import assert_equal, assert_not_equal, \
14-
assert_true, assert_false, assert_raises
13+
import nibabel
1514

16-
from numpy.testing import (assert_array_equal,
17-
assert_array_almost_equal)
15+
from ..ecat import EcatHeader, EcatMlist, EcatSubHeader, EcatImage
1816

17+
from unittest import TestCase
1918

20-
from ..ecat import EcatHeader, EcatMlist, EcatSubHeader, EcatImage
21-
import test_binary as tb
22-
from ..testing import parametric, data_path, ParametricTestCase
19+
from nose.tools import (assert_true, assert_false, assert_equal,
20+
assert_not_equal, assert_raises)
21+
22+
from numpy.testing import assert_array_equal, assert_array_almost_equal
2323

24-
ecat_file = os.path.join(data_path, 'tinypet.v')
24+
data_path = os.path.dirname(nibabel.__file__)
25+
ecat_file = os.path.join(data_path, 'tests','data','tinypet.v')
2526

26-
class TestEcatHeader(ParametricTestCase):
27+
class TestEcatHeader(TestCase):
2728
header_class = EcatHeader
2829
example_file = ecat_file
2930

3031
def test_header_size(self):
31-
yield assert_equal(self.header_class._dtype.itemsize, 502)
32+
assert_equal(self.header_class._dtype.itemsize, 502)
3233

3334
def test_empty(self):
3435
hdr = self.header_class()
35-
yield assert_true(len(hdr.binaryblock) == 502)
36-
yield assert_true(hdr['magic_number'] == 'MATRIX72')
37-
yield assert_true(hdr['sw_version'] == 74)
38-
yield assert_true(hdr['num_frames'] == 0)
39-
yield assert_true(hdr['file_type'] == 0)
40-
yield assert_true(hdr['ecat_calibration_factor'] == 1.0)
41-
36+
assert_true(len(hdr.binaryblock) == 502)
37+
assert_true(hdr['magic_number'] == 'MATRIX72')
38+
assert_true(hdr['sw_version'] == 74)
39+
assert_true(hdr['num_frames'] == 0)
40+
assert_true(hdr['file_type'] == 0)
41+
assert_true(hdr['ecat_calibration_factor'] == 1.0)
42+
4243
def test_dtype(self):
4344
#dtype not specified in header, only in subheaders
4445
hdr = self.header_class()
45-
yield assert_raises(NotImplementedError,
46+
assert_raises(NotImplementedError,
4647
hdr.get_data_dtype)
4748

4849
def test_header_codes(self):
4950
fid = open(ecat_file)
5051
hdr = self.header_class()
5152
newhdr = hdr.from_fileobj(fid)
5253
fid.close()
53-
yield assert_true(newhdr.get_filetype() == 'ECAT7_VOLUME16')
54-
yield assert_equal(newhdr.get_patient_orient(),
54+
assert_true(newhdr.get_filetype() == 'ECAT7_VOLUME16')
55+
assert_equal(newhdr.get_patient_orient(),
5556
'ECAT7_Unknown_Orientation')
5657

5758
def test_copy(self):
5859
hdr = self.header_class()
5960
hdr2 = hdr.copy()
60-
yield assert_true(hdr == hdr2)
61-
yield assert_true(not hdr.binaryblock == hdr2._header_data.byteswap().tostring())
62-
yield assert_true(hdr.keys() == hdr2.keys())
63-
61+
assert_true(hdr == hdr2)
62+
assert_true(not hdr.binaryblock == hdr2._header_data.byteswap().tostring())
63+
assert_true(hdr.keys() == hdr2.keys())
64+
6465
def test_update(self):
6566
hdr = self.header_class()
66-
yield assert_true(hdr['num_frames'] == 0)
67+
assert_true(hdr['num_frames'] == 0)
6768
hdr['num_frames'] = 2
68-
yield assert_true(hdr['num_frames'] == 2)
69+
assert_true(hdr['num_frames'] == 2)
6970

7071
def test_endianness(self):
7172
fid = open(ecat_file)
7273
hdr = self.header_class()
7374
newhdr = hdr.from_fileobj(fid)
7475
fid.close()
75-
yield assert_true(hdr.endianness == '<')
76-
yield assert_true(newhdr.endianness == '>')
77-
78-
class TestEcatMlist(ParametricTestCase):
76+
assert_true(hdr.endianness == '<')
77+
assert_true(newhdr.endianness == '>')
78+
79+
class TestEcatMlist(TestCase):
7980
header_class = EcatHeader
8081
mlist_class = EcatMlist
8182
example_file = ecat_file
@@ -91,11 +92,11 @@ def test_mlist(self):
9192
dt = dt.newbyteorder('>')
9293
mats = np.recarray(shape=(32,4), dtype=dt, buf=dat)
9394
fid.close()
94-
yield assert_true(mats['matlist'][0,0] + mats['matlist'][0,3] == 31)
95-
yield assert_true(mlist.get_frame_order()[0][0] == 0)
96-
yield assert_true(mlist.get_frame_order()[0][1] == 16842758.0)
97-
98-
class TestEcatSubHeader(ParametricTestCase):
95+
assert_true(mats['matlist'][0,0] + mats['matlist'][0,3] == 31)
96+
assert_true(mlist.get_frame_order()[0][0] == 0)
97+
assert_true(mlist.get_frame_order()[0][1] == 16842758.0)
98+
99+
class TestEcatSubHeader(TestCase):
99100
header_class = EcatHeader
100101
mlist_class = EcatMlist
101102
subhdr_class = EcatSubHeader
@@ -107,47 +108,50 @@ class TestEcatSubHeader(ParametricTestCase):
107108

108109

109110
def test_subheader_size(self):
110-
yield assert_equal(self.subhdr_class._subhdrdtype.itemsize, 242)
111+
assert_equal(self.subhdr_class._subhdrdtype.itemsize, 242)
111112

112113
def test_subheader(self):
113-
yield assert_equal(self.subhdr.get_shape() , (10,10,3))
114-
yield assert_equal(self.subhdr.get_nframes() , 1)
115-
yield assert_equal(self.subhdr.get_nframes(),
116-
len(self.subhdr.subheaders))
117-
yield assert_equal(self.subhdr._check_affines(), True)
118-
yield assert_array_almost_equal(np.diag(self.subhdr.get_frame_affine()),
119-
np.array([ 2.20241979, 2.20241979, 3.125, 1.]))
120-
yield assert_equal(self.subhdr.get_zooms()[0], 2.20241978764534)
121-
yield assert_equal(self.subhdr.get_zooms()[2], 3.125)
122-
yield assert_equal(self.subhdr._get_data_dtype(0),np.uint16)
123-
yield assert_equal(self.subhdr._get_frame_offset(), 1536)
114+
assert_equal(self.subhdr.get_shape() , (10,10,3))
115+
assert_equal(self.subhdr.get_nframes() , 1)
116+
assert_equal(self.subhdr.get_nframes(),
117+
len(self.subhdr.subheaders))
118+
assert_equal(self.subhdr._check_affines(), True)
119+
assert_array_almost_equal(np.diag(self.subhdr.get_frame_affine()),
120+
np.array([ 2.20241979, 2.20241979, 3.125, 1.]))
121+
assert_equal(self.subhdr.get_zooms()[0], 2.20241978764534)
122+
assert_equal(self.subhdr.get_zooms()[2], 3.125)
123+
assert_equal(self.subhdr._get_data_dtype(0),np.uint16)
124+
assert_equal(self.subhdr._get_frame_offset(), 1536)
124125
dat = self.subhdr.raw_data_from_fileobj()
125-
yield assert_equal(dat.shape, self.subhdr.get_shape())
126+
assert_equal(dat.shape, self.subhdr.get_shape())
126127
scale_factor = self.subhdr.subheaders[0]['scale_factor']
128+
assert_equal(self.subhdr.subheaders[0]['scale_factor'].item(),1.0)
129+
127130
ecat_calib_factor = self.hdr['ecat_calibration_factor']
131+
assert_equal(ecat_calib_factor, 25007614.0)
128132
scaled_dat = self.subhdr.data_from_fileobj()
129-
yield assert_array_equal(dat * scale_factor * ecat_calib_factor,
130-
scaled_dat)
133+
tmpdat = scale_factor * ecat_calib_factor * dat
134+
assert_array_equal(tmpdat, scaled_dat)
131135

132136

133-
class TestEcatImage(ParametricTestCase):
137+
class TestEcatImage(TestCase):
134138
image_class = EcatImage
135139
example_file = ecat_file
136140
img = image_class.load(example_file)
137141

138142
def test_file(self):
139-
yield assert_equal(self.img.file_map['header'].filename,
140-
self.example_file)
141-
yield assert_equal(self.img.file_map['image'].filename,
142-
self.example_file)
143-
yield assert_raises(NotImplementedError,
144-
self.img.to_filename,
145-
'tmp.v')
143+
assert_equal(self.img.file_map['header'].filename,
144+
self.example_file)
145+
assert_equal(self.img.file_map['image'].filename,
146+
self.example_file)
147+
assert_raises(NotImplementedError,
148+
self.img.to_filename,
149+
'tmp.v')
146150

147151
def test_data(self):
148152
dat = self.img.get_data()
149-
yield assert_equal(dat.shape, self.img.get_shape())
153+
assert_equal(dat.shape, self.img.get_shape())
150154
frame = self.img.get_frame(0)
151-
yield assert_array_equal(frame, dat[:,:,:,0])
155+
assert_array_equal(frame, dat[:,:,:,0])
152156

153157

0 commit comments

Comments
 (0)