Skip to content

Commit d27b124

Browse files
committed
fixes to assert numpy
1 parent 6e1e1c1 commit d27b124

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

nibabel/freesurfer/tests/test_io.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def test_geometry():
6161
assert 0 == faces.min()
6262
assert coords.shape[0] == (faces.max() + 1)
6363
assert 9 == len(volume_info)
64-
assert [2, 0, 20] == volume_info['head']
65-
assert ['created by greve on Thu Jun 8 19:17:51 2006'] == create_stamp
64+
# assert np.array_equal([2, 0, 20],volume_info['head'])
65+
np.testing.assert_array_equal([2, 0, 20],volume_info['head'])
66+
assert create_stamp == ['created by greve on Thu Jun 8 19:17:51 2006'] # this creates assertion error - should we just remove it?
6667

6768
# Test equivalence of freesurfer- and nibabel-generated triangular files
6869
# with respect to read_geometry()
@@ -79,7 +80,8 @@ def test_geometry():
7980
for key in ('xras', 'yras', 'zras', 'cras'):
8081
assert_allclose(volume_info2[key], volume_info[key],
8182
rtol=1e-7, atol=1e-30)
82-
assert volume_info2['cras'] == volume_info['cras']
83+
#assert.array_equal(volume_info2['cras'], volume_info['cras'])
84+
np.testing.assert_array_equal(volume_info2['cras'], volume_info['cras'])
8385
with open(surf_path, 'rb') as fobj:
8486
np.fromfile(fobj, ">u1", 3)
8587
read_create_stamp = fobj.readline().decode().rstrip('\n')
@@ -126,8 +128,8 @@ def test_quad_geometry():
126128
new_path = 'test'
127129
write_geometry(new_path, coords, faces)
128130
coords2, faces2 = read_geometry(new_path)
129-
assert coords == coords2
130-
assert faces == faces2
131+
assert np.array_equal(coords,coords2)
132+
assert np.array_equal(faces, faces2)
131133

132134

133135
@freesurfer_test
@@ -141,7 +143,7 @@ def test_morph_data():
141143
new_path = 'test'
142144
write_morph_data(new_path, curv)
143145
curv2 = read_morph_data(new_path)
144-
assert curv2 == curv
146+
assert np.array_equal (curv2, curv)
145147

146148

147149
def test_write_morph_data():
@@ -154,7 +156,7 @@ def test_write_morph_data():
154156
for shape in okay_shapes:
155157
write_morph_data('test.curv', values.reshape(shape))
156158
# Check ordering is preserved, regardless of shape
157-
assert values == read_morph_data('test.curv')
159+
assert np.array_equal(read_morph_data('test.curv') ,values)
158160
with pytest.raises(ValueError):
159161
write_morph_data('test.curv', np.zeros(shape), big_num)
160162
# Windows 32-bit overflows Python int

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import pytest
2828

29-
from numpy.testing import (assert_array_equal, assert_array_almost_equal, assert_almost_equal)
29+
from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal
3030

3131

3232
from ...testing_pytest import data_path
@@ -218,14 +218,14 @@ def test_header_updating():
218218
assert_almost_equal(mgz.affine, exp_aff, 6)
219219
assert_almost_equal(hdr.get_affine(), exp_aff, 6)
220220
# Test that initial wonky header elements have not changed
221-
assert hdr['delta'] == 1
221+
assert_array_equal(hdr['delta'], 1)
222222
assert_almost_equal(hdr['Mdc'].T, exp_aff[:3, :3])
223223
# Save, reload, same thing
224224
img_fobj = io.BytesIO()
225225
mgz2 = _mgh_rt(mgz, img_fobj)
226226
hdr2 = mgz2.header
227227
assert_almost_equal(hdr2.get_affine(), exp_aff, 6)
228-
assert hdr2['delta'] == 1
228+
assert_array_equal(hdr2['delta'],1)
229229
# Change affine, change underlying header info
230230
exp_aff_d = exp_aff.copy()
231231
exp_aff_d[0, -1] = -14

0 commit comments

Comments
 (0)