1010from nibabel .tmpdirs import InTemporaryDirectory
1111from numpy .compat .py3k import asbytes
1212
13- from nibabel .testing import data_path
14- from nibabel .testing import clear_and_catch_warnings
15- from nose .tools import assert_equal , assert_raises , assert_true , assert_false
13+ from nibabel .testing import data_path , clear_and_catch_warnings
1614
1715from .test_tractogram import assert_tractogram_equal
1816from ..tractogram import Tractogram , LazyTractogram
@@ -82,50 +80,50 @@ def test_is_supported_detect_format():
8280 # Test is_supported and detect_format functions
8381 # Empty file/string
8482 f = BytesIO ()
85- assert_false ( nib .streamlines .is_supported (f ) )
86- assert_false ( nib .streamlines .is_supported ("" ) )
87- assert_true ( nib .streamlines .detect_format (f ) is None )
88- assert_true ( nib .streamlines .detect_format ("" ) is None )
83+ assert not nib .streamlines .is_supported (f )
84+ assert not nib .streamlines .is_supported ("" )
85+ assert nib .streamlines .detect_format (f ) is None
86+ assert nib .streamlines .detect_format ("" ) is None
8987
9088 # Valid file without extension
9189 for tfile_cls in FORMATS .values ():
9290 f = BytesIO ()
9391 f .write (asbytes (tfile_cls .MAGIC_NUMBER ))
9492 f .seek (0 , os .SEEK_SET )
95- assert_true ( nib .streamlines .is_supported (f ) )
96- assert_true ( nib .streamlines .detect_format (f ) is tfile_cls )
93+ assert nib .streamlines .is_supported (f )
94+ assert nib .streamlines .detect_format (f ) is tfile_cls
9795
9896 # Wrong extension but right magic number
9997 for tfile_cls in FORMATS .values ():
10098 with tempfile .TemporaryFile (mode = "w+b" , suffix = ".txt" ) as f :
10199 f .write (asbytes (tfile_cls .MAGIC_NUMBER ))
102100 f .seek (0 , os .SEEK_SET )
103- assert_true ( nib .streamlines .is_supported (f ) )
104- assert_true ( nib .streamlines .detect_format (f ) is tfile_cls )
101+ assert nib .streamlines .is_supported (f )
102+ assert nib .streamlines .detect_format (f ) is tfile_cls
105103
106104 # Good extension but wrong magic number
107105 for ext , tfile_cls in FORMATS .items ():
108106 with tempfile .TemporaryFile (mode = "w+b" , suffix = ext ) as f :
109107 f .write (b"pass" )
110108 f .seek (0 , os .SEEK_SET )
111- assert_false ( nib .streamlines .is_supported (f ) )
112- assert_true ( nib .streamlines .detect_format (f ) is None )
109+ assert not nib .streamlines .is_supported (f )
110+ assert nib .streamlines .detect_format (f ) is None
113111
114112 # Wrong extension, string only
115113 f = "my_tractogram.asd"
116- assert_false ( nib .streamlines .is_supported (f ) )
117- assert_true ( nib .streamlines .detect_format (f ) is None )
114+ assert not nib .streamlines .is_supported (f )
115+ assert nib .streamlines .detect_format (f ) is None
118116
119117 # Good extension, string only
120118 for ext , tfile_cls in FORMATS .items ():
121119 f = "my_tractogram" + ext
122- assert_true ( nib .streamlines .is_supported (f ) )
123- assert_equal ( nib .streamlines .detect_format (f ), tfile_cls )
120+ assert nib .streamlines .is_supported (f )
121+ assert nib .streamlines .detect_format (f ) == tfile_cls
124122
125123 # Extension should not be case-sensitive.
126124 for ext , tfile_cls in FORMATS .items ():
127125 f = "my_tractogram" + ext .upper ()
128- assert_true ( nib .streamlines .detect_format (f ) is tfile_cls )
126+ assert nib .streamlines .detect_format (f ) is tfile_cls
129127
130128
131129class TestLoadSave (unittest .TestCase ):
@@ -135,12 +133,12 @@ def test_load_empty_file(self):
135133 for empty_filename in DATA ['empty_filenames' ]:
136134 tfile = nib .streamlines .load (empty_filename ,
137135 lazy_load = lazy_load )
138- assert_true ( isinstance (tfile , TractogramFile ) )
136+ assert isinstance (tfile , TractogramFile )
139137
140138 if lazy_load :
141- assert_true ( type (tfile .tractogram ), Tractogram )
139+ assert type (tfile .tractogram ), Tractogram
142140 else :
143- assert_true ( type (tfile .tractogram ), LazyTractogram )
141+ assert type (tfile .tractogram ), LazyTractogram
144142
145143 assert_tractogram_equal (tfile .tractogram ,
146144 DATA ['empty_tractogram' ])
@@ -150,12 +148,12 @@ def test_load_simple_file(self):
150148 for simple_filename in DATA ['simple_filenames' ]:
151149 tfile = nib .streamlines .load (simple_filename ,
152150 lazy_load = lazy_load )
153- assert_true ( isinstance (tfile , TractogramFile ) )
151+ assert isinstance (tfile , TractogramFile )
154152
155153 if lazy_load :
156- assert_true ( type (tfile .tractogram ), Tractogram )
154+ assert type (tfile .tractogram ), Tractogram
157155 else :
158- assert_true ( type (tfile .tractogram ), LazyTractogram )
156+ assert type (tfile .tractogram ), LazyTractogram
159157
160158 assert_tractogram_equal (tfile .tractogram ,
161159 DATA ['simple_tractogram' ])
@@ -165,12 +163,12 @@ def test_load_complex_file(self):
165163 for complex_filename in DATA ['complex_filenames' ]:
166164 tfile = nib .streamlines .load (complex_filename ,
167165 lazy_load = lazy_load )
168- assert_true ( isinstance (tfile , TractogramFile ) )
166+ assert isinstance (tfile , TractogramFile )
169167
170168 if lazy_load :
171- assert_true ( type (tfile .tractogram ), Tractogram )
169+ assert type (tfile .tractogram ), Tractogram
172170 else :
173- assert_true ( type (tfile .tractogram ), LazyTractogram )
171+ assert type (tfile .tractogram ), LazyTractogram
174172
175173 tractogram = Tractogram (DATA ['streamlines' ],
176174 affine_to_rasmm = np .eye (4 ))
@@ -191,19 +189,19 @@ def test_save_tractogram_file(self):
191189 trk_file = trk .TrkFile (tractogram )
192190
193191 # No need for keyword arguments.
194- assert_raises ( ValueError , nib . streamlines . save ,
195- trk_file , "dummy.trk" , header = {})
192+ with self . assertRaises ( ValueError ):
193+ nib . streamlines . save ( trk_file , "dummy.trk" , header = {})
196194
197195 # Wrong extension.
198196 with clear_and_catch_warnings (record = True ,
199197 modules = [nib .streamlines ]) as w :
200198 trk_file = trk .TrkFile (tractogram )
201- assert_raises ( ValueError , nib . streamlines . save ,
202- trk_file , "dummy.tck" , header = {})
199+ with self . assertRaises ( ValueError ):
200+ nib . streamlines . save ( trk_file , "dummy.tck" , header = {})
203201
204- assert_equal ( len (w ), 1 )
205- assert_true ( issubclass (w [0 ].category , ExtensionWarning ) )
206- assert_true ( "extension" in str (w [0 ].message ) )
202+ assert len (w ) == 1
203+ assert issubclass (w [0 ].category , ExtensionWarning )
204+ assert "extension" in str (w [0 ].message )
207205
208206 with InTemporaryDirectory ():
209207 nib .streamlines .save (trk_file , "dummy.trk" )
@@ -250,9 +248,9 @@ def test_save_complex_file(self):
250248 ((not cls .SUPPORTS_DATA_PER_POINT ) +
251249 (not cls .SUPPORTS_DATA_PER_STREAMLINE ))
252250
253- assert_equal ( len (w ), nb_expected_warnings )
251+ assert len (w ) == nb_expected_warnings
254252 for i in range (nb_expected_warnings ):
255- assert_true ( issubclass (w [i ].category , Warning ) )
253+ assert issubclass (w [i ].category , Warning )
256254
257255 tractogram = Tractogram (DATA ['streamlines' ],
258256 affine_to_rasmm = np .eye (4 ))
@@ -281,10 +279,12 @@ def test_save_sliced_tractogram(self):
281279 assert_tractogram_equal (tractogram , original_tractogram )
282280
283281 def test_load_unknown_format (self ):
284- assert_raises (ValueError , nib .streamlines .load , "" )
282+ with self .assertRaises (ValueError ):
283+ nib .streamlines .load ("" )
285284
286285 def test_save_unknown_format (self ):
287- assert_raises (ValueError , nib .streamlines .save , Tractogram (), "" )
286+ with self .assertRaises (ValueError ):
287+ nib .streamlines .save (Tractogram (), "" )
288288
289289 def test_save_from_generator (self ):
290290 tractogram = Tractogram (DATA ['streamlines' ],
0 commit comments