Skip to content

Commit c7fad2e

Browse files
committed
TEST: Suppress warnings in freesurfer
1 parent 8903f0b commit c7fad2e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

nibabel/freesurfer/tests/test_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ def test_geometry():
8686

8787
# now write an incomplete file
8888
write_geometry(surf_path, coords, faces)
89-
with clear_and_catch_warnings() as w:
89+
with pytest.warns(Warning) as w:
9090
warnings.filterwarnings('always', category=DeprecationWarning)
9191
read_geometry(surf_path, read_metadata=True)
9292

9393
assert any('volume information contained' in str(ww.message) for ww in w)
9494
assert any('extension code' in str(ww.message) for ww in w)
9595
volume_info['head'] = [1, 2]
96-
with clear_and_catch_warnings() as w:
96+
with pytest.warns(Warning) as w:
9797
write_geometry(surf_path, coords, faces, create_stamp, volume_info)
9898
assert any('Unknown extension' in str(ww.message) for ww in w)
9999
volume_info['a'] = 0
@@ -266,7 +266,7 @@ def test_write_annot_fill_ctab():
266266
# values back.
267267
badannot = (10 * np.arange(nlabels, dtype=np.int32)).reshape(-1, 1)
268268
rgbal = np.hstack((rgba, badannot))
269-
with clear_and_catch_warnings() as w:
269+
with pytest.warns(Warning) as w:
270270
write_annot(annot_path, labels, rgbal, names, fill_ctab=False)
271271
assert any(f'Annotation values in {annot_path} will be incorrect' == str(ww.message)
272272
for ww in w)

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,14 @@ def test_deprecated_fields():
345345

346346
# mrparams is the only deprecated field at the moment
347347
# Accessing hdr_data is equivalent to accessing hdr, so double all checks
348-
assert_array_equal(hdr['mrparams'], 0)
348+
with pytest.deprecated_call():
349+
assert_array_equal(hdr['mrparams'], 0)
349350
assert_array_equal(hdr_data['mrparams'], 0)
350351

351-
hdr['mrparams'] = [1, 2, 3, 4]
352-
assert_array_almost_equal(hdr['mrparams'], [1, 2, 3, 4])
352+
with pytest.deprecated_call():
353+
hdr['mrparams'] = [1, 2, 3, 4]
354+
with pytest.deprecated_call():
355+
assert_array_almost_equal(hdr['mrparams'], [1, 2, 3, 4])
353356
assert hdr['tr'] == 1
354357
assert hdr['flip_angle'] == 2
355358
assert hdr['te'] == 3
@@ -366,14 +369,16 @@ def test_deprecated_fields():
366369
hdr['flip_angle'] = 6
367370
hdr['te'] = 7
368371
hdr['ti'] = 8
369-
assert_array_almost_equal(hdr['mrparams'], [5, 6, 7, 8])
372+
with pytest.deprecated_call():
373+
assert_array_almost_equal(hdr['mrparams'], [5, 6, 7, 8])
370374
assert_array_almost_equal(hdr_data['mrparams'], [5, 6, 7, 8])
371375

372376
hdr_data['tr'] = 9
373377
hdr_data['flip_angle'] = 10
374378
hdr_data['te'] = 11
375379
hdr_data['ti'] = 12
376-
assert_array_almost_equal(hdr['mrparams'], [9, 10, 11, 12])
380+
with pytest.deprecated_call():
381+
assert_array_almost_equal(hdr['mrparams'], [9, 10, 11, 12])
377382
assert_array_almost_equal(hdr_data['mrparams'], [9, 10, 11, 12])
378383

379384

0 commit comments

Comments
 (0)