77
88import numpy as np
99
10+ from ...pydicom_compat import pydicom
1011from .. import csareader as csa
1112from .. import dwiparams as dwp
1213
13- from nose .tools import (assert_true , assert_false , assert_equal , assert_raises )
14-
15- from ...testing import skipif
16-
17- from nibabel .pydicom_compat import dicom_test , pydicom
18- from .test_dicomwrappers import (IO_DATA_PATH , DATA )
14+ import pytest
15+ from . import dicom_test
16+ from .test_dicomwrappers import IO_DATA_PATH , DATA
1917
2018CSA2_B0 = open (pjoin (IO_DATA_PATH , 'csa2_b0.bin' ), 'rb' ).read ()
2119CSA2_B1000 = open (pjoin (IO_DATA_PATH , 'csa2_b1000.bin' ), 'rb' ).read ()
2725@dicom_test
2826def test_csa_header_read ():
2927 hdr = csa .get_csa_header (DATA , 'image' )
30- assert_equal (hdr ['n_tags' ], 83 )
31- assert_equal (csa .get_csa_header (DATA , 'series' )['n_tags' ], 65 )
32- assert_raises (ValueError , csa .get_csa_header , DATA , 'xxxx' )
33- assert_true (csa .is_mosaic (hdr ))
28+ assert hdr ['n_tags' ] == 83
29+ assert csa .get_csa_header (DATA , 'series' )['n_tags' ] == 65
30+ with pytest .raises (ValueError ):
31+ csa .get_csa_header (DATA , 'xxxx' )
32+ assert csa .is_mosaic (hdr )
3433 # Get a shallow copy of the data, lacking the CSA marker
3534 # Need to do it this way because del appears broken in pydicom 0.9.7
3635 data2 = pydicom .dataset .Dataset ()
3736 for element in DATA :
3837 if (element .tag .group , element .tag .elem ) != (0x29 , 0x10 ):
3938 data2 .add (element )
40- assert_equal ( csa .get_csa_header (data2 , 'image' ), None )
39+ assert csa .get_csa_header (data2 , 'image' ) is None
4140 # Add back the marker - CSA works again
4241 data2 [(0x29 , 0x10 )] = DATA [(0x29 , 0x10 )]
43- assert_true ( csa .is_mosaic (csa .get_csa_header (data2 , 'image' ) ))
42+ assert csa .is_mosaic (csa .get_csa_header (data2 , 'image' ))
4443
4544
4645def test_csas0 ():
4746 for csa_str in (CSA2_B0 , CSA2_B1000 ):
4847 csa_info = csa .read (csa_str )
49- assert_equal ( csa_info ['type' ], 2 )
50- assert_equal ( csa_info ['n_tags' ], 83 )
48+ assert csa_info ['type' ] == 2
49+ assert csa_info ['n_tags' ] == 83
5150 tags = csa_info ['tags' ]
52- assert_equal ( len (tags ), 83 )
51+ assert len (tags ) == 83
5352 n_o_m = tags ['NumberOfImagesInMosaic' ]
54- assert_equal ( n_o_m ['items' ], [48 ])
53+ assert n_o_m ['items' ] == [48 ]
5554 csa_info = csa .read (CSA2_B1000 )
5655 b_matrix = csa_info ['tags' ]['B_matrix' ]
57- assert_equal ( len (b_matrix ['items' ]), 6 )
56+ assert len (b_matrix ['items' ]) == 6
5857 b_value = csa_info ['tags' ]['B_value' ]
59- assert_equal ( b_value ['items' ], [1000 ])
58+ assert b_value ['items' ] == [1000 ]
6059
6160
6261def test_csa_len0 ():
6362 # We did get a failure for item with item_len of 0 - gh issue #92
6463 csa_info = csa .read (CSA2_0len )
65- assert_equal ( csa_info ['type' ], 2 )
66- assert_equal ( csa_info ['n_tags' ], 44 )
64+ assert csa_info ['type' ] == 2
65+ assert csa_info ['n_tags' ] == 44
6766 tags = csa_info ['tags' ]
68- assert_equal ( len (tags ), 44 )
67+ assert len (tags ) == 44
6968
7069
7170def test_csa_nitem ():
7271 # testing csa.read's ability to raise an error when n_items >= 200
73- assert_raises (csa .CSAReadError , csa .read , CSA_STR_1001n_items )
72+ with pytest .raises (csa .CSAReadError ):
73+ csa .read (CSA_STR_1001n_items )
7474 # OK when < 1000
7575 csa_info = csa .read (CSA_STR_valid )
76- assert_equal ( len (csa_info ['tags' ]), 1 )
76+ assert len (csa_info ['tags' ]) == 1
7777 # OK after changing module global
7878 n_items_thresh = csa .MAX_CSA_ITEMS
7979 try :
8080 csa .MAX_CSA_ITEMS = 2000
8181 csa_info = csa .read (CSA_STR_1001n_items )
82- assert_equal ( len (csa_info ['tags' ]), 1 )
82+ assert len (csa_info ['tags' ]) == 1
8383 finally :
8484 csa .MAX_CSA_ITEMS = n_items_thresh
8585
@@ -88,32 +88,30 @@ def test_csa_params():
8888 for csa_str in (CSA2_B0 , CSA2_B1000 ):
8989 csa_info = csa .read (csa_str )
9090 n_o_m = csa .get_n_mosaic (csa_info )
91- assert_equal ( n_o_m , 48 )
91+ assert n_o_m == 48
9292 snv = csa .get_slice_normal (csa_info )
93- assert_equal (snv .shape , (3 ,))
94- assert_true (np .allclose (1 ,
95- np .sqrt ((snv * snv ).sum ())))
93+ assert snv .shape == (3 ,)
94+ assert np .allclose (1 , np .sqrt ((snv * snv ).sum ()))
9695 amt = csa .get_acq_mat_txt (csa_info )
97- assert_equal ( amt , '128p*128' )
96+ assert amt == '128p*128'
9897 csa_info = csa .read (CSA2_B0 )
9998 b_matrix = csa .get_b_matrix (csa_info )
100- assert_equal ( b_matrix , None )
99+ assert b_matrix is None
101100 b_value = csa .get_b_value (csa_info )
102- assert_equal ( b_value , 0 )
101+ assert b_value == 0
103102 g_vector = csa .get_g_vector (csa_info )
104- assert_equal ( g_vector , None )
103+ assert g_vector is None
105104 csa_info = csa .read (CSA2_B1000 )
106105 b_matrix = csa .get_b_matrix (csa_info )
107- assert_equal ( b_matrix .shape , (3 , 3 ) )
106+ assert b_matrix .shape == (3 , 3 )
108107 # check (by absence of error) that the B matrix is positive
109108 # semi-definite.
110109 dwp .B2q (b_matrix ) # no error
111110 b_value = csa .get_b_value (csa_info )
112- assert_equal ( b_value , 1000 )
111+ assert b_value == 1000
113112 g_vector = csa .get_g_vector (csa_info )
114- assert_equal (g_vector .shape , (3 ,))
115- assert_true (
116- np .allclose (1 , np .sqrt ((g_vector * g_vector ).sum ())))
113+ assert g_vector .shape == (3 ,)
114+ assert np .allclose (1 , np .sqrt ((g_vector * g_vector ).sum ()))
117115
118116
119117def test_ice_dims ():
@@ -124,9 +122,8 @@ def test_ice_dims():
124122 for csa_str , ex_dims in ((CSA2_B0 , ex_dims0 ),
125123 (CSA2_B1000 , ex_dims1 )):
126124 csa_info = csa .read (csa_str )
127- assert_equal (csa .get_ice_dims (csa_info ),
128- ex_dims )
129- assert_equal (csa .get_ice_dims ({}), None )
125+ assert csa .get_ice_dims (csa_info ) == ex_dims
126+ assert csa .get_ice_dims ({}) is None
130127
131128
132129@dicom_test
@@ -138,4 +135,4 @@ def test_missing_csa_elem():
138135 csa_tag = pydicom .dataset .Tag (0x29 , 0x1010 )
139136 del dcm [csa_tag ]
140137 hdr = csa .get_csa_header (dcm , 'image' )
141- assert_equal ( hdr , None )
138+ assert hdr is None
0 commit comments