5
5
Test running scripts
6
6
"""
7
7
8
- from nose .tools import assert_equal
9
8
from numpy .testing import assert_raises
10
9
10
+ import pytest
11
+
11
12
import nibabel as nib
12
13
import numpy as np
13
14
from nibabel .cmdline .utils import *
19
20
20
21
21
22
def test_table2string ():
22
- assert_equal ( table2string ([["A" , "B" , "C" , "D" ], ["E" , "F" , "G" , "H" ]]), "A B C D\n E F G H\n " )
23
- assert_equal ( table2string ([["Let's" , "Make" , "Tests" , "And" ], ["Have" , "Lots" , "Of" , "Fun" ],
24
- ["With" , "Python" , "Guys" , "!" ]]), "Let's Make Tests And\n Have Lots Of Fun" +
25
- "\n With Python Guys !\n " )
23
+ assert table2string ([["A" , "B" , "C" , "D" ], ["E" , "F" , "G" , "H" ]]) == "A B C D\n E F G H\n "
24
+ assert table2string ([["Let's" , "Make" , "Tests" , "And" ], ["Have" , "Lots" , "Of" , "Fun" ],
25
+ ["With" , "Python" , "Guys" , "!" ]]) == "Let's Make Tests And\n Have Lots Of Fun" + \
26
+ "\n With Python Guys !\n "
26
27
27
28
28
29
def test_ap ():
29
- assert_equal ( ap ([1 , 2 ], "%2d" ), " 1, 2" )
30
- assert_equal ( ap ([1 , 2 ], "%3d" ), " 1, 2" )
31
- assert_equal ( ap ([1 , 2 ], "%-2d" ), "1 , 2 " )
32
- assert_equal ( ap ([1 , 2 ], "%d" , "+" ), "1+2" )
33
- assert_equal ( ap ([1 , 2 , 3 ], "%d" , "-" ), "1-2-3" )
30
+ assert ap ([1 , 2 ], "%2d" ) == " 1, 2"
31
+ assert ap ([1 , 2 ], "%3d" ) == " 1, 2"
32
+ assert ap ([1 , 2 ], "%-2d" ) == "1 , 2 "
33
+ assert ap ([1 , 2 ], "%d" , "+" ) == "1+2"
34
+ assert ap ([1 , 2 , 3 ], "%d" , "-" ) == "1-2-3"
34
35
35
36
36
37
def test_safe_get ():
@@ -44,8 +45,8 @@ def get_test(self):
44
45
test = TestObject ()
45
46
test .test = 2
46
47
47
- assert_equal ( safe_get (test , "test" ), 2 )
48
- assert_equal ( safe_get (test , "failtest" ), "-" )
48
+ assert safe_get (test , "test" ) == 2
49
+ assert safe_get (test , "failtest" ) == "-"
49
50
50
51
51
52
def test_get_headers_diff ():
@@ -107,14 +108,14 @@ def test_display_diff():
107
108
" " \
108
109
"\n "
109
110
110
- assert_equal ( display_diff (bogus_names , dict_values ), expected_output )
111
+ assert display_diff (bogus_names , dict_values ) == expected_output
111
112
112
113
113
114
def test_get_data_diff ():
114
115
# testing for identical files specifically as md5 may vary by computer
115
116
test_names = [pjoin (data_path , f )
116
117
for f in ('standard.nii.gz' , 'standard.nii.gz' )]
117
- assert_equal ( get_data_hash_diff (test_names ), [])
118
+ assert get_data_hash_diff (test_names ) == []
118
119
119
120
# testing the maximum relative and absolute differences' different use cases
120
121
test_array = np .arange (16 ).reshape (4 , 4 )
@@ -124,37 +125,37 @@ def test_get_data_diff():
124
125
test_array_5 = np .arange (64 ).reshape (8 , 8 )
125
126
126
127
# same shape, 2 files
127
- assert_equal ( get_data_diff ([test_array , test_array_2 ]),
128
- OrderedDict ([('DATA(diff 1:)' , [None , OrderedDict ([('abs' , 1 ), ('rel' , 2.0 )])])]))
128
+ assert get_data_diff ([test_array , test_array_2 ]) == \
129
+ OrderedDict ([('DATA(diff 1:)' , [None , OrderedDict ([('abs' , 1 ), ('rel' , 2.0 )])])])
129
130
130
131
# same shape, 3 files
131
- assert_equal ( get_data_diff ([test_array , test_array_2 , test_array_3 ]),
132
+ assert get_data_diff ([test_array , test_array_2 , test_array_3 ]) == \
132
133
OrderedDict ([('DATA(diff 1:)' , [None , OrderedDict ([('abs' , 1 ), ('rel' , 2.0 )]),
133
134
OrderedDict ([('abs' , 2 ), ('rel' , 2.0 )])]),
134
135
('DATA(diff 2:)' , [None , None ,
135
- OrderedDict ([('abs' , 1 ), ('rel' , 0.66666666666666663 )])])]))
136
+ OrderedDict ([('abs' , 1 ), ('rel' , 0.66666666666666663 )])])])
136
137
137
138
# same shape, 2 files, modified maximum abs/rel
138
- assert_equal ( get_data_diff ([test_array , test_array_2 ], max_abs = 2 , max_rel = 2 ), OrderedDict () )
139
+ assert get_data_diff ([test_array , test_array_2 ], max_abs = 2 , max_rel = 2 ) == OrderedDict ()
139
140
140
141
# different shape, 2 files
141
- assert_equal ( get_data_diff ([test_array_2 , test_array_4 ]),
142
- OrderedDict ([('DATA(diff 1:)' , [None , {'CMP' : 'incompat' }])]))
142
+ assert get_data_diff ([test_array_2 , test_array_4 ]) == \
143
+ OrderedDict ([('DATA(diff 1:)' , [None , {'CMP' : 'incompat' }])])
143
144
144
145
# different shape, 3 files
145
- assert_equal ( get_data_diff ([test_array_4 , test_array_5 , test_array_2 ]),
146
+ assert get_data_diff ([test_array_4 , test_array_5 , test_array_2 ]) == \
146
147
OrderedDict ([('DATA(diff 1:)' , [None , {'CMP' : 'incompat' }, {'CMP' : 'incompat' }]),
147
- ('DATA(diff 2:)' , [None , None , {'CMP' : 'incompat' }])]))
148
+ ('DATA(diff 2:)' , [None , None , {'CMP' : 'incompat' }])])
148
149
149
150
test_return = get_data_diff ([test_array , test_array_2 ], dtype = np .float32 )
150
- assert_equal ( type (test_return ['DATA(diff 1:)' ][1 ]['abs' ]), np .float32 )
151
- assert_equal ( type (test_return ['DATA(diff 1:)' ][1 ]['rel' ]), np .float32 )
151
+ assert type (test_return ['DATA(diff 1:)' ][1 ]['abs' ]) is np .float32
152
+ assert type (test_return ['DATA(diff 1:)' ][1 ]['rel' ]) is np .float32
152
153
153
154
test_return_2 = get_data_diff ([test_array , test_array_2 , test_array_3 ])
154
- assert_equal ( type (test_return_2 ['DATA(diff 1:)' ][1 ]['abs' ]), np .float64 )
155
- assert_equal ( type (test_return_2 ['DATA(diff 1:)' ][1 ]['rel' ]), np .float64 )
156
- assert_equal ( type (test_return_2 ['DATA(diff 2:)' ][2 ]['abs' ]), np .float64 )
157
- assert_equal ( type (test_return_2 ['DATA(diff 2:)' ][2 ]['rel' ]), np .float64 )
155
+ assert type (test_return_2 ['DATA(diff 1:)' ][1 ]['abs' ]) is np .float64
156
+ assert type (test_return_2 ['DATA(diff 1:)' ][1 ]['rel' ]) is np .float64
157
+ assert type (test_return_2 ['DATA(diff 2:)' ][2 ]['abs' ]) is np .float64
158
+ assert type (test_return_2 ['DATA(diff 2:)' ][2 ]['rel' ]) is np .float64
158
159
159
160
160
161
def test_main ():
@@ -201,4 +202,4 @@ def test_main():
201
202
test_names_2 = [pjoin (data_path , f ) for f in ('standard.nii.gz' , 'standard.nii.gz' )]
202
203
203
204
with assert_raises (SystemExit ):
204
- assert_equal ( main (test_names_2 , StringIO ()), "These files are identical." )
205
+ assert main (test_names_2 , StringIO ()) == "These files are identical."
0 commit comments