Skip to content

Commit 441e4fe

Browse files
committed
changed from numpy raises to pytest.raises and skipif
1 parent 665b28a commit 441e4fe

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

nibabel/freesurfer/tests/test_io.py

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
import pytest
1414
import numpy as np
15-
from numpy.testing import assert_equal, assert_raises, dec, assert_allclose, assert_array_equal
15+
from numpy.testing import assert_allclose, assert_array_equal
1616

1717
from .. import (read_geometry, read_morph_data, read_annot, read_label,
1818
write_geometry, write_morph_data, write_annot)
1919
from ..io import _pack_rgb
2020

2121
from ...tests.nibabel_data import get_nibabel_data, needs_nibabel_data
2222
from ...fileslice import strided_scalar
23-
from ...testing import clear_and_catch_warnings
23+
from ...testing_pytest import clear_and_catch_warnings
2424

2525
DATA_SDIR = 'fsaverage'
2626

@@ -36,10 +36,7 @@
3636
data_path = pjoin(nib_data, 'nitest-freesurfer', DATA_SDIR)
3737
have_freesurfer = isdir(data_path)
3838

39-
freesurfer_test = dec.skipif(
40-
not have_freesurfer,
41-
'cannot find freesurfer {0} directory'.format(DATA_SDIR))
42-
39+
freesurfer_test = pytest.mark.skipif(not have_freesurfer, reason='cannot find freesurfer {0} directory'.format(DATA_SDIR))
4340

4441
def _hash_file_content(fname):
4542
hasher = hashlib.md5()
@@ -54,19 +51,18 @@ def test_geometry():
5451
"""Test IO of .surf"""
5552
surf_path = pjoin(data_path, "surf", "%s.%s" % ("lh", "inflated"))
5653
coords, faces = read_geometry(surf_path)
57-
assert_equal(0, faces.min())
58-
assert_equal(coords.shape[0], faces.max() + 1)
54+
assert 0==faces.min()
55+
assert coords.shape[0]== faces.max() + 1
5956

6057
surf_path = pjoin(data_path, "surf", "%s.%s" % ("lh", "sphere"))
6158
coords, faces, volume_info, create_stamp = read_geometry(
6259
surf_path, read_metadata=True, read_stamp=True)
6360

64-
assert_equal(0, faces.min())
65-
assert_equal(coords.shape[0], faces.max() + 1)
66-
assert_equal(9, len(volume_info))
67-
assert_equal([2, 0, 20], volume_info['head'])
68-
assert_equal(u'created by greve on Thu Jun 8 19:17:51 2006',
69-
create_stamp)
61+
assert 0 == faces.min()
62+
assert coords.shape[0] == faces.max() + 1
63+
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
7066

7167
# Test equivalence of freesurfer- and nibabel-generated triangular files
7268
# with respect to read_geometry()
@@ -83,7 +79,7 @@ def test_geometry():
8379
for key in ('xras', 'yras', 'zras', 'cras'):
8480
assert_allclose(volume_info2[key], volume_info[key],
8581
rtol=1e-7, atol=1e-30)
86-
assert_equal(volume_info2['cras'], volume_info['cras'])
82+
assert volume_info2['cras'] == volume_info['cras']
8783
with open(surf_path, 'rb') as fobj:
8884
np.fromfile(fobj, ">u1", 3)
8985
read_create_stamp = fobj.readline().decode().rstrip('\n')
@@ -101,10 +97,11 @@ def test_geometry():
10197
write_geometry(surf_path, coords, faces, create_stamp, volume_info)
10298
assert(any('Unknown extension' in str(ww.message) for ww in w))
10399
volume_info['a'] = 0
104-
assert_raises(ValueError, write_geometry, surf_path, coords,
105-
faces, create_stamp, volume_info)
100+
with pytest.raises(ValueError):
101+
write_geometry(surf_path, coords, faces, create_stamp, volume_info)
102+
106103

107-
assert_equal(create_stamp, read_create_stamp)
104+
assert create_stamp == read_create_stamp
108105

109106
np.testing.assert_array_equal(coords, coords2)
110107
np.testing.assert_array_equal(faces, faces2)
@@ -123,14 +120,14 @@ def test_quad_geometry():
123120
new_quad = pjoin(get_nibabel_data(), 'nitest-freesurfer', 'subjects',
124121
'bert', 'surf', 'lh.inflated.nofix')
125122
coords, faces = read_geometry(new_quad)
126-
assert_equal(0, faces.min())
127-
assert_equal(coords.shape[0], faces.max() + 1)
123+
assert 0 == faces.min()
124+
assert coords.shape[0] == faces.max() + 1
128125
with InTemporaryDirectory():
129126
new_path = 'test'
130127
write_geometry(new_path, coords, faces)
131128
coords2, faces2 = read_geometry(new_path)
132-
assert_equal(coords, coords2)
133-
assert_equal(faces, faces2)
129+
assert coords == coords2
130+
assert faces == faces2
134131

135132

136133
@freesurfer_test
@@ -144,7 +141,7 @@ def test_morph_data():
144141
new_path = 'test'
145142
write_morph_data(new_path, curv)
146143
curv2 = read_morph_data(new_path)
147-
assert_equal(curv2, curv)
144+
assert curv2 == curv
148145

149146

150147
def test_write_morph_data():
@@ -157,17 +154,17 @@ def test_write_morph_data():
157154
for shape in okay_shapes:
158155
write_morph_data('test.curv', values.reshape(shape))
159156
# Check ordering is preserved, regardless of shape
160-
assert_equal(values, read_morph_data('test.curv'))
161-
assert_raises(ValueError, write_morph_data, 'test.curv',
162-
np.zeros(shape), big_num)
163-
# Windows 32-bit overflows Python int
157+
assert values == read_morph_data('test.curv')
158+
with pytest.raises(ValueError):
159+
write_morph_data('test.curv', np.zeros(shape), big_num)
160+
# Windows 32-bit overflows Python int
164161
if np.dtype(np.int) != np.dtype(np.int32):
165-
assert_raises(ValueError, write_morph_data, 'test.curv',
166-
strided_scalar((big_num,)))
162+
with pytest.raises(ValueError):
163+
write_morph_data('test.curv', strided_scalar((big_num,)))
167164
for shape in bad_shapes:
168-
assert_raises(ValueError, write_morph_data, 'test.curv',
169-
values.reshape(shape))
170-
165+
with pytest.raises(ValueError):
166+
write_morph_data('test.curv', values.reshape(shape))
167+
171168

172169
@freesurfer_test
173170
def test_annot():
@@ -208,7 +205,7 @@ def test_annot():
208205
if labels_orig is not None:
209206
np.testing.assert_array_equal(labels_orig, labels_orig_2)
210207
np.testing.assert_array_equal(ctab, ctab2)
211-
assert_equal(names, names2)
208+
assert names == names2
212209

213210

214211
def test_read_write_annot():
@@ -374,4 +371,4 @@ def test_write_annot_maxstruct():
374371
# Check round-trip
375372
assert_array_equal(labels, rt_labels)
376373
assert_array_equal(rgba, rt_ctab[:, :4])
377-
assert_equal(names, [n.decode('ascii') for n in rt_names])
374+
assert names == [n.decode('ascii') for n in rt_names]

0 commit comments

Comments
 (0)