Skip to content

Commit 0117212

Browse files
committed
TEST: Remove last imports of nose
1 parent 8db1cd9 commit 0117212

File tree

4 files changed

+62
-55
lines changed

4 files changed

+62
-55
lines changed

nibabel/nicom/tests/test_dwiparams.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
from ..dwiparams import B2q, q2bg
88

9-
from nose.tools import (assert_true, assert_false, assert_equal, assert_raises)
9+
import pytest
1010

11-
from numpy.testing import (assert_array_equal, assert_array_almost_equal,
12-
assert_equal as np_assert_equal)
11+
from numpy.testing import (assert_array_almost_equal, assert_equal as np_assert_equal)
1312

1413

1514
def test_b2q():
@@ -27,17 +26,20 @@ def test_b2q():
2726
assert_array_almost_equal(-q * s, B2q(B))
2827
# Massive negative eigs
2928
B = np.eye(3) * -1
30-
assert_raises(ValueError, B2q, B)
29+
with pytest.raises(ValueError):
30+
B2q(B)
3131
# no error if we up the tolerance
3232
q = B2q(B, tol=1)
3333
# Less massive negativity, dropping tol
3434
B = np.diag([-1e-14, 10., 1])
35-
assert_raises(ValueError, B2q, B)
35+
with pytest.raises(ValueError):
36+
B2q(B)
3637
assert_array_almost_equal(B2q(B, tol=5e-13), [0, 10, 0])
3738
# Confirm that we assume symmetric
3839
B = np.eye(3)
3940
B[0, 1] = 1e-5
40-
assert_raises(ValueError, B2q, B)
41+
with pytest.raises(ValueError):
42+
B2q(B)
4143

4244

4345
def test_q2bg():

nibabel/streamlines/tests/test_streamlines.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
from nibabel.tmpdirs import InTemporaryDirectory
1111
from 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

1715
from .test_tractogram import assert_tractogram_equal
1816
from ..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

131129
class 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'],

nibabel/streamlines/tests/test_tractogram_file.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ..tractogram import Tractogram
55
from ..tractogram_file import TractogramFile
66

7-
from nose.tools import assert_raises, assert_equal
7+
import pytest
88

99

1010
def test_subclassing_tractogram_file():
@@ -23,7 +23,8 @@ def load(cls, fileobj, lazy_load=True):
2323
def create_empty_header(cls):
2424
return None
2525

26-
assert_raises(TypeError, DummyTractogramFile, Tractogram())
26+
with pytest.raises(TypeError):
27+
DummyTractogramFile(Tractogram())
2728

2829
# Missing 'load' method
2930
class DummyTractogramFile(TractogramFile):
@@ -38,7 +39,8 @@ def save(self, fileobj):
3839
def create_empty_header(cls):
3940
return None
4041

41-
assert_raises(TypeError, DummyTractogramFile, Tractogram())
42+
with pytest.raises(TypeError):
43+
DummyTractogramFile(Tractogram())
4244

4345
# Now we have everything required.
4446
class DummyTractogramFile(TractogramFile):
@@ -57,12 +59,14 @@ def save(self, fileobj):
5759
dtf = DummyTractogramFile(Tractogram())
5860

5961
# Default create_empty_header is empty dict
60-
assert_equal(dtf.header, {})
62+
assert dtf.header == {}
6163

6264

6365
def test_tractogram_file():
64-
assert_raises(NotImplementedError, TractogramFile.is_correct_format, "")
65-
assert_raises(NotImplementedError, TractogramFile.load, "")
66+
with pytest.raises(NotImplementedError):
67+
TractogramFile.is_correct_format("")
68+
with pytest.raises(NotImplementedError):
69+
TractogramFile.load("")
6670

6771
# Testing calling the 'save' method of `TractogramFile` object.
6872
class DummyTractogramFile(TractogramFile):
@@ -78,6 +82,5 @@ def load(cls, fileobj, lazy_load=True):
7882
def save(self, fileobj):
7983
pass
8084

81-
assert_raises(NotImplementedError,
82-
super(DummyTractogramFile,
83-
DummyTractogramFile(Tractogram)).save, "")
85+
with pytest.raises(NotImplementedError):
86+
super(DummyTractogramFile, DummyTractogramFile(Tractogram)).save("")

nibabel/streamlines/tests/test_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from nibabel.testing import data_path
66
from numpy.testing import assert_array_equal
7-
from nose.tools import assert_raises
7+
8+
import pytest
89

910
from ..utils import get_affine_from_reference
1011

@@ -17,7 +18,8 @@ def test_get_affine_from_reference():
1718
# Get affine from an numpy array.
1819
assert_array_equal(get_affine_from_reference(affine), affine)
1920
wrong_ref = np.array([[1, 2, 3], [4, 5, 6]])
20-
assert_raises(ValueError, get_affine_from_reference, wrong_ref)
21+
with pytest.raises(ValueError):
22+
get_affine_from_reference(wrong_ref)
2123

2224
# Get affine from a `SpatialImage`.
2325
assert_array_equal(get_affine_from_reference(img), affine)

0 commit comments

Comments
 (0)