Skip to content

Commit f1bfc39

Browse files
committed
TEST: Simplify lazy_load conditional warning check
1 parent 4707222 commit f1bfc39

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

nibabel/streamlines/tests/test_streamlines.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ def test_load_empty_file(self):
142142
else:
143143
assert type(tfile.tractogram), LazyTractogram
144144

145-
with pytest.warns(None) as w:
145+
with pytest.warns(Warning if lazy_load else None):
146146
assert_tractogram_equal(tfile.tractogram,
147147
DATA['empty_tractogram'])
148-
assert len(w) == lazy_load
149148

150149
def test_load_simple_file(self):
151150
for lazy_load in [False, True]:
@@ -159,10 +158,9 @@ def test_load_simple_file(self):
159158
else:
160159
assert type(tfile.tractogram), LazyTractogram
161160

162-
with pytest.warns(None) as w:
161+
with pytest.warns(Warning if lazy_load else None):
163162
assert_tractogram_equal(tfile.tractogram,
164163
DATA['simple_tractogram'])
165-
assert len(w) == lazy_load
166164

167165
def test_load_complex_file(self):
168166
for lazy_load in [False, True]:
@@ -186,10 +184,9 @@ def test_load_complex_file(self):
186184
data = DATA['data_per_streamline']
187185
tractogram.data_per_streamline = data
188186

189-
with pytest.warns(None) as w:
187+
with pytest.warns(Warning if lazy_load else None):
190188
assert_tractogram_equal(tfile.tractogram,
191189
tractogram)
192-
assert len(w) == lazy_load
193190

194191
def test_save_tractogram_file(self):
195192
tractogram = Tractogram(DATA['streamlines'],

nibabel/streamlines/tests/test_tck.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ class TestTCK(unittest.TestCase):
4747
def test_load_empty_file(self):
4848
for lazy_load in [False, True]:
4949
tck = TckFile.load(DATA['empty_tck_fname'], lazy_load=lazy_load)
50-
with pytest.warns(None) as w:
50+
with pytest.warns(Warning if lazy_load else None):
5151
assert_tractogram_equal(tck.tractogram, DATA['empty_tractogram'])
52-
assert len(w) == lazy_load
5352

5453
def test_load_simple_file(self):
5554
for lazy_load in [False, True]:
5655
tck = TckFile.load(DATA['simple_tck_fname'], lazy_load=lazy_load)
57-
with pytest.warns(None) as w:
56+
with pytest.warns(Warning if lazy_load else None):
5857
assert_tractogram_equal(tck.tractogram, DATA['simple_tractogram'])
59-
assert len(w) == lazy_load
6058

6159
# Force TCK loading to use buffering.
6260
buffer_size = 1. / 1024**2 # 1 bytes
@@ -90,9 +88,8 @@ def test_load_simple_file_in_big_endian(self):
9088
for lazy_load in [False, True]:
9189
tck = TckFile.load(DATA['simple_tck_big_endian_fname'],
9290
lazy_load=lazy_load)
93-
with pytest.warns(None) as w:
91+
with pytest.warns(Warning if lazy_load else None):
9492
assert_tractogram_equal(tck.tractogram, DATA['simple_tractogram'])
95-
assert len(w) == lazy_load
9693
assert tck.header['datatype'] == 'Float32BE'
9794

9895
def test_load_file_with_wrong_information(self):

nibabel/streamlines/tests/test_trk.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,20 @@ class TestTRK(unittest.TestCase):
8787
def test_load_empty_file(self):
8888
for lazy_load in [False, True]:
8989
trk = TrkFile.load(DATA['empty_trk_fname'], lazy_load=lazy_load)
90-
with pytest.warns(None) as w:
90+
with pytest.warns(Warning if lazy_load else None):
9191
assert_tractogram_equal(trk.tractogram, DATA['empty_tractogram'])
92-
assert len(w) == lazy_load
9392

9493
def test_load_simple_file(self):
9594
for lazy_load in [False, True]:
9695
trk = TrkFile.load(DATA['simple_trk_fname'], lazy_load=lazy_load)
97-
with pytest.warns(None) as w:
96+
with pytest.warns(Warning if lazy_load else None):
9897
assert_tractogram_equal(trk.tractogram, DATA['simple_tractogram'])
99-
assert len(w) == lazy_load
10098

10199
def test_load_complex_file(self):
102100
for lazy_load in [False, True]:
103101
trk = TrkFile.load(DATA['complex_trk_fname'], lazy_load=lazy_load)
104-
with pytest.warns(None) as w:
102+
with pytest.warns(Warning if lazy_load else None):
105103
assert_tractogram_equal(trk.tractogram, DATA['complex_tractogram'])
106-
assert len(w) == lazy_load
107104

108105
def trk_with_bytes(self, trk_key='simple_trk_fname', endian='<'):
109106
""" Return example trk file bytes and struct view onto bytes """
@@ -202,9 +199,8 @@ def test_load_complex_file_in_big_endian(self):
202199
for lazy_load in [False, True]:
203200
trk = TrkFile.load(DATA['complex_trk_big_endian_fname'],
204201
lazy_load=lazy_load)
205-
with pytest.warns(None) as w:
202+
with pytest.warns(Warning if lazy_load else None):
206203
assert_tractogram_equal(trk.tractogram, DATA['complex_tractogram'])
207-
assert len(w) == lazy_load
208204

209205
def test_tractogram_file_properties(self):
210206
trk = TrkFile.load(DATA['simple_trk_fname'])

0 commit comments

Comments
 (0)