12
12
13
13
import pytest
14
14
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
16
16
17
17
from .. import (read_geometry , read_morph_data , read_annot , read_label ,
18
18
write_geometry , write_morph_data , write_annot )
19
19
from ..io import _pack_rgb
20
20
21
21
from ...tests .nibabel_data import get_nibabel_data , needs_nibabel_data
22
22
from ...fileslice import strided_scalar
23
- from ...testing import clear_and_catch_warnings
23
+ from ...testing_pytest import clear_and_catch_warnings
24
24
25
25
DATA_SDIR = 'fsaverage'
26
26
36
36
data_path = pjoin (nib_data , 'nitest-freesurfer' , DATA_SDIR )
37
37
have_freesurfer = isdir (data_path )
38
38
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 ))
43
40
44
41
def _hash_file_content (fname ):
45
42
hasher = hashlib .md5 ()
@@ -54,19 +51,18 @@ def test_geometry():
54
51
"""Test IO of .surf"""
55
52
surf_path = pjoin (data_path , "surf" , "%s.%s" % ("lh" , "inflated" ))
56
53
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
59
56
60
57
surf_path = pjoin (data_path , "surf" , "%s.%s" % ("lh" , "sphere" ))
61
58
coords , faces , volume_info , create_stamp = read_geometry (
62
59
surf_path , read_metadata = True , read_stamp = True )
63
60
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
70
66
71
67
# Test equivalence of freesurfer- and nibabel-generated triangular files
72
68
# with respect to read_geometry()
@@ -83,7 +79,7 @@ def test_geometry():
83
79
for key in ('xras' , 'yras' , 'zras' , 'cras' ):
84
80
assert_allclose (volume_info2 [key ], volume_info [key ],
85
81
rtol = 1e-7 , atol = 1e-30 )
86
- assert_equal ( volume_info2 ['cras' ], volume_info ['cras' ])
82
+ assert volume_info2 ['cras' ] == volume_info ['cras' ]
87
83
with open (surf_path , 'rb' ) as fobj :
88
84
np .fromfile (fobj , ">u1" , 3 )
89
85
read_create_stamp = fobj .readline ().decode ().rstrip ('\n ' )
@@ -101,10 +97,11 @@ def test_geometry():
101
97
write_geometry (surf_path , coords , faces , create_stamp , volume_info )
102
98
assert (any ('Unknown extension' in str (ww .message ) for ww in w ))
103
99
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
+
106
103
107
- assert_equal ( create_stamp , read_create_stamp )
104
+ assert create_stamp == read_create_stamp
108
105
109
106
np .testing .assert_array_equal (coords , coords2 )
110
107
np .testing .assert_array_equal (faces , faces2 )
@@ -123,14 +120,14 @@ def test_quad_geometry():
123
120
new_quad = pjoin (get_nibabel_data (), 'nitest-freesurfer' , 'subjects' ,
124
121
'bert' , 'surf' , 'lh.inflated.nofix' )
125
122
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
128
125
with InTemporaryDirectory ():
129
126
new_path = 'test'
130
127
write_geometry (new_path , coords , faces )
131
128
coords2 , faces2 = read_geometry (new_path )
132
- assert_equal ( coords , coords2 )
133
- assert_equal ( faces , faces2 )
129
+ assert coords == coords2
130
+ assert faces == faces2
134
131
135
132
136
133
@freesurfer_test
@@ -144,7 +141,7 @@ def test_morph_data():
144
141
new_path = 'test'
145
142
write_morph_data (new_path , curv )
146
143
curv2 = read_morph_data (new_path )
147
- assert_equal ( curv2 , curv )
144
+ assert curv2 == curv
148
145
149
146
150
147
def test_write_morph_data ():
@@ -157,17 +154,17 @@ def test_write_morph_data():
157
154
for shape in okay_shapes :
158
155
write_morph_data ('test.curv' , values .reshape (shape ))
159
156
# 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
164
161
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 ,)))
167
164
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
+
171
168
172
169
@freesurfer_test
173
170
def test_annot ():
@@ -208,7 +205,7 @@ def test_annot():
208
205
if labels_orig is not None :
209
206
np .testing .assert_array_equal (labels_orig , labels_orig_2 )
210
207
np .testing .assert_array_equal (ctab , ctab2 )
211
- assert_equal ( names , names2 )
208
+ assert names == names2
212
209
213
210
214
211
def test_read_write_annot ():
@@ -374,4 +371,4 @@ def test_write_annot_maxstruct():
374
371
# Check round-trip
375
372
assert_array_equal (labels , rt_labels )
376
373
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