7
7
8
8
import numpy as np
9
9
10
+ from ...pydicom_compat import pydicom
10
11
from .. import csareader as csa
11
12
from .. import dwiparams as dwp
12
13
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
19
17
20
18
CSA2_B0 = open (pjoin (IO_DATA_PATH , 'csa2_b0.bin' ), 'rb' ).read ()
21
19
CSA2_B1000 = open (pjoin (IO_DATA_PATH , 'csa2_b1000.bin' ), 'rb' ).read ()
27
25
@dicom_test
28
26
def test_csa_header_read ():
29
27
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 )
34
33
# Get a shallow copy of the data, lacking the CSA marker
35
34
# Need to do it this way because del appears broken in pydicom 0.9.7
36
35
data2 = pydicom .dataset .Dataset ()
37
36
for element in DATA :
38
37
if (element .tag .group , element .tag .elem ) != (0x29 , 0x10 ):
39
38
data2 .add (element )
40
- assert_equal ( csa .get_csa_header (data2 , 'image' ), None )
39
+ assert csa .get_csa_header (data2 , 'image' ) is None
41
40
# Add back the marker - CSA works again
42
41
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' ))
44
43
45
44
46
45
def test_csas0 ():
47
46
for csa_str in (CSA2_B0 , CSA2_B1000 ):
48
47
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
51
50
tags = csa_info ['tags' ]
52
- assert_equal ( len (tags ), 83 )
51
+ assert len (tags ) == 83
53
52
n_o_m = tags ['NumberOfImagesInMosaic' ]
54
- assert_equal ( n_o_m ['items' ], [48 ])
53
+ assert n_o_m ['items' ] == [48 ]
55
54
csa_info = csa .read (CSA2_B1000 )
56
55
b_matrix = csa_info ['tags' ]['B_matrix' ]
57
- assert_equal ( len (b_matrix ['items' ]), 6 )
56
+ assert len (b_matrix ['items' ]) == 6
58
57
b_value = csa_info ['tags' ]['B_value' ]
59
- assert_equal ( b_value ['items' ], [1000 ])
58
+ assert b_value ['items' ] == [1000 ]
60
59
61
60
62
61
def test_csa_len0 ():
63
62
# We did get a failure for item with item_len of 0 - gh issue #92
64
63
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
67
66
tags = csa_info ['tags' ]
68
- assert_equal ( len (tags ), 44 )
67
+ assert len (tags ) == 44
69
68
70
69
71
70
def test_csa_nitem ():
72
71
# 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 )
74
74
# OK when < 1000
75
75
csa_info = csa .read (CSA_STR_valid )
76
- assert_equal ( len (csa_info ['tags' ]), 1 )
76
+ assert len (csa_info ['tags' ]) == 1
77
77
# OK after changing module global
78
78
n_items_thresh = csa .MAX_CSA_ITEMS
79
79
try :
80
80
csa .MAX_CSA_ITEMS = 2000
81
81
csa_info = csa .read (CSA_STR_1001n_items )
82
- assert_equal ( len (csa_info ['tags' ]), 1 )
82
+ assert len (csa_info ['tags' ]) == 1
83
83
finally :
84
84
csa .MAX_CSA_ITEMS = n_items_thresh
85
85
@@ -88,32 +88,30 @@ def test_csa_params():
88
88
for csa_str in (CSA2_B0 , CSA2_B1000 ):
89
89
csa_info = csa .read (csa_str )
90
90
n_o_m = csa .get_n_mosaic (csa_info )
91
- assert_equal ( n_o_m , 48 )
91
+ assert n_o_m == 48
92
92
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 ()))
96
95
amt = csa .get_acq_mat_txt (csa_info )
97
- assert_equal ( amt , '128p*128' )
96
+ assert amt == '128p*128'
98
97
csa_info = csa .read (CSA2_B0 )
99
98
b_matrix = csa .get_b_matrix (csa_info )
100
- assert_equal ( b_matrix , None )
99
+ assert b_matrix is None
101
100
b_value = csa .get_b_value (csa_info )
102
- assert_equal ( b_value , 0 )
101
+ assert b_value == 0
103
102
g_vector = csa .get_g_vector (csa_info )
104
- assert_equal ( g_vector , None )
103
+ assert g_vector is None
105
104
csa_info = csa .read (CSA2_B1000 )
106
105
b_matrix = csa .get_b_matrix (csa_info )
107
- assert_equal ( b_matrix .shape , (3 , 3 ) )
106
+ assert b_matrix .shape == (3 , 3 )
108
107
# check (by absence of error) that the B matrix is positive
109
108
# semi-definite.
110
109
dwp .B2q (b_matrix ) # no error
111
110
b_value = csa .get_b_value (csa_info )
112
- assert_equal ( b_value , 1000 )
111
+ assert b_value == 1000
113
112
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 ()))
117
115
118
116
119
117
def test_ice_dims ():
@@ -124,9 +122,8 @@ def test_ice_dims():
124
122
for csa_str , ex_dims in ((CSA2_B0 , ex_dims0 ),
125
123
(CSA2_B1000 , ex_dims1 )):
126
124
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
130
127
131
128
132
129
@dicom_test
@@ -138,4 +135,4 @@ def test_missing_csa_elem():
138
135
csa_tag = pydicom .dataset .Tag (0x29 , 0x1010 )
139
136
del dcm [csa_tag ]
140
137
hdr = csa .get_csa_header (dcm , 'image' )
141
- assert_equal ( hdr , None )
138
+ assert hdr is None
0 commit comments