|
10 | 10 | from ..orientations import aff2axcodes |
11 | 11 | from ..volumeutils import native_code, swapped_code |
12 | 12 |
|
13 | | -from nose.tools import assert_true, assert_false, assert_equal, assert_raises |
14 | | -from numpy.testing import assert_array_equal, assert_array_almost_equal |
15 | | -from ..testing import error_warnings, suppress_warnings |
| 13 | +from numpy.testing import assert_array_almost_equal |
| 14 | +from ..testing import (assert_true, assert_false, assert_equal, assert_raises, assert_warns, |
| 15 | + assert_array_equal, suppress_warnings) |
16 | 16 |
|
17 | 17 |
|
18 | 18 | def test_write(): |
@@ -217,8 +217,7 @@ def _rt(streams, hdr, points_space): |
217 | 217 | assert_raises(tv.HeaderError, tv.read, out_f, False, 'voxel') |
218 | 218 | # There's a warning for any voxel sizes == 0 |
219 | 219 | hdr = {'voxel_size': [2, 3, 0]} |
220 | | - with error_warnings(): |
221 | | - assert_raises(UserWarning, _rt, vx_streams, hdr, 'voxel') |
| 220 | + assert_warns(UserWarning, _rt, vx_streams, hdr, 'voxel') |
222 | 221 | # This should be OK |
223 | 222 | hdr = {'voxel_size': [2, 3, 4]} |
224 | 223 | (raw_streams, hdr), (proc_streams, _) = _rt(vx_streams, hdr, 'voxel') |
@@ -305,9 +304,8 @@ def test__check_hdr_points_space(): |
305 | 304 | tv._check_hdr_points_space, hdr, 'voxel') |
306 | 305 | # Warning here only |
307 | 306 | hdr['voxel_size'] = [2, 3, 0] |
308 | | - with error_warnings(): |
309 | | - assert_raises(UserWarning, |
310 | | - tv._check_hdr_points_space, hdr, 'voxel') |
| 307 | + assert_warns(UserWarning, |
| 308 | + tv._check_hdr_points_space, hdr, 'voxel') |
311 | 309 | # This is OK |
312 | 310 | hdr['voxel_size'] = [2, 3, 4] |
313 | 311 | assert_equal(tv._check_hdr_points_space(hdr, 'voxel'), None) |
@@ -370,10 +368,6 @@ def test_empty_header(): |
370 | 368 | def test_get_affine(): |
371 | 369 | # Test get affine behavior, including pending deprecation |
372 | 370 | hdr = tv.empty_header() |
373 | | - # Using version 1 affine is not a good idea because is fragile and not |
374 | | - # very useful. The default atleast_v2=None mode raises a FutureWarning |
375 | | - with error_warnings(): |
376 | | - assert_raises(FutureWarning, tv.aff_from_hdr, hdr) |
377 | 371 | # testing the old behavior |
378 | 372 | old_afh = partial(tv.aff_from_hdr, atleast_v2=False) |
379 | 373 | # default header gives useless affine |
@@ -421,9 +415,8 @@ def test_get_affine(): |
421 | 415 | assert_equal(hdr['voxel_order'], o_codes) |
422 | 416 | # Check it came back the way we wanted |
423 | 417 | assert_array_equal(old_afh(hdr), in_aff) |
424 | | - # Check that the default case matches atleast_v2=False case |
425 | | - with suppress_warnings(): |
426 | | - assert_array_equal(tv.aff_from_hdr(hdr), flipped_aff) |
| 418 | + # Check that v1 header raises error |
| 419 | + assert_raises(tv.HeaderError, tv.aff_from_hdr, hdr) |
427 | 420 | # now use the easier vox_to_ras field |
428 | 421 | hdr = tv.empty_header() |
429 | 422 | aff = np.eye(4) |
@@ -455,15 +448,7 @@ def test_aff_to_hdr(): |
455 | 448 | # Historically we flip the first axis if there is a negative determinant |
456 | 449 | assert_array_almost_equal(hdr['voxel_size'], [-1, 2, 3]) |
457 | 450 | assert_array_almost_equal(tv.aff_from_hdr(hdr, atleast_v2=False), aff2) |
458 | | - # Test that default mode raises DeprecationWarning |
459 | | - with error_warnings(): |
460 | | - assert_raises(FutureWarning, tv.aff_to_hdr, affine, hdr) |
461 | | - assert_raises(FutureWarning, tv.aff_to_hdr, affine, hdr, None, None) |
462 | | - assert_raises(FutureWarning, tv.aff_to_hdr, affine, hdr, False, None) |
463 | | - assert_raises(FutureWarning, tv.aff_to_hdr, affine, hdr, None, False) |
464 | | - # And has same effect as above |
465 | | - with suppress_warnings(): |
466 | | - tv.aff_to_hdr(affine, hdr) |
| 451 | + tv.aff_to_hdr(affine, hdr, pos_vox=False, set_order=False) |
467 | 452 | assert_array_almost_equal(tv.aff_from_hdr(hdr, atleast_v2=False), affine) |
468 | 453 | # Check pos_vox and order flags |
469 | 454 | for hdr in ({}, {'version': 2}, {'version': 1}): |
@@ -515,13 +500,6 @@ def test_tv_class(): |
515 | 500 | affine = np.diag([1, 2, 3, 1]) |
516 | 501 | affine[:3, 3] = [10, 11, 12] |
517 | 502 | # affine methods will raise same warnings and errors as function |
518 | | - with error_warnings(): |
519 | | - assert_raises(FutureWarning, tvf.set_affine, affine) |
520 | | - assert_raises(FutureWarning, tvf.set_affine, affine, None, None) |
521 | | - assert_raises(FutureWarning, tvf.set_affine, affine, False, None) |
522 | | - assert_raises(FutureWarning, tvf.set_affine, affine, None, False) |
523 | | - assert_raises(FutureWarning, tvf.get_affine) |
524 | | - assert_raises(FutureWarning, tvf.get_affine, None) |
525 | 503 | tvf.set_affine(affine, pos_vox=True, set_order=True) |
526 | 504 | aff = tvf.get_affine(atleast_v2=True) |
527 | 505 | assert_array_almost_equal(aff, affine) |
|
0 commit comments