Skip to content

Commit a9bbe82

Browse files
committed
small cleaning after review
1 parent 2539bcd commit a9bbe82

File tree

8 files changed

+37
-41
lines changed

8 files changed

+37
-41
lines changed

nibabel/tests/test_arraywriters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def test_writer_maker():
640640
assert (aw.slope, aw.inter) == (1, 0)
641641
aw.calc_scale()
642642
slope, inter = aw.slope, aw.inter
643-
assert (slope, inter) != (1, 0)
643+
assert not (slope, inter) == (1, 0)
644644
# Should run by default
645645
aw = make_array_writer(arr, np.int16)
646646
assert (aw.slope, aw.inter) == (slope, inter)
@@ -704,7 +704,7 @@ def test_int_int_slope():
704704
aw = SlopeArrayWriter(arr, out_dt)
705705
except ScalingError:
706706
continue
707-
assert aw.slope != 0
707+
assert not aw.slope == 0
708708
arr_back_sc = round_trip(aw)
709709
# integer allclose
710710
adiff = int_abs(arr - arr_back_sc)

nibabel/tests/test_casting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_casting():
120120
# Confirm input array is not modified
121121
nans = np.isnan(farr)
122122
assert_array_equal(nans, np.isnan(farr_orig))
123-
assert_array_equal(farr[nans is False], farr_orig[nans is False])
123+
assert_array_equal(farr[nans == False], farr_orig[nans == False])
124124
# Test scalars work and return scalars
125125
assert_array_equal(float_to_int(np.float32(0), np.int16), [0])
126126
# Test scalar nan OK

nibabel/tests/test_deprecator.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def test__add_dep_doc():
3434
assert _add_dep_doc('bar\n\n', 'foo') == 'bar\n\nfoo\n'
3535
assert _add_dep_doc('bar\n \n', 'foo') == 'bar\n\nfoo\n'
3636
assert (_add_dep_doc(' bar\n\nSome explanation', 'foo\nbaz') ==
37-
' bar\n\nfoo\nbaz\n\nSome explanation\n')
37+
' bar\n\nfoo\nbaz\n\nSome explanation\n')
3838
assert (_add_dep_doc(' bar\n\n Some explanation', 'foo\nbaz') ==
39-
' bar\n \n foo\n baz\n \n Some explanation\n')
39+
' bar\n \n foo\n baz\n \n Some explanation\n')
4040

4141

4242
class CustomError(Exception):
@@ -73,28 +73,24 @@ def test_dep_func(self):
7373
assert func() is None
7474
assert func.__doc__ == 'foo\n'
7575
func = dec('foo')(func_doc)
76-
with clear_and_catch_warnings(modules=[_OWN_MODULE]) as w:
77-
warnings.simplefilter('always')
76+
with pytest.deprecated_call() as w:
7877
assert func(1) is None
7978
assert len(w) == 1
8079
assert func.__doc__ == 'A docstring\n\nfoo\n'
8180
func = dec('foo')(func_doc_long)
82-
with clear_and_catch_warnings(modules=[_OWN_MODULE]) as w:
83-
warnings.simplefilter('always')
81+
with pytest.deprecated_call() as w:
8482
assert func(1, 2) is None
8583
assert len(w) == 1
8684
assert func.__doc__ == 'A docstring\n \n foo\n \n Some text\n'
8785

8886
# Try some since and until versions
8987
func = dec('foo', '1.1')(func_no_doc)
9088
assert func.__doc__ == 'foo\n\n* deprecated from version: 1.1\n'
91-
with clear_and_catch_warnings(modules=[_OWN_MODULE]) as w:
92-
warnings.simplefilter('always')
89+
with pytest.deprecated_call() as w:
9390
assert func() is None
9491
assert len(w) == 1
9592
func = dec('foo', until='99.4')(func_no_doc)
96-
with clear_and_catch_warnings(modules=[_OWN_MODULE]) as w:
97-
warnings.simplefilter('always')
93+
with pytest.deprecated_call() as w:
9894
assert func() is None
9995
assert len(w) == 1
10096
assert (func.__doc__ ==
@@ -104,22 +100,22 @@ def test_dep_func(self):
104100
with pytest.raises(ExpiredDeprecationError):
105101
func()
106102
assert (func.__doc__ ==
107-
'foo\n\n* Raises {} as of version: 1.8\n'
108-
.format(ExpiredDeprecationError))
103+
'foo\n\n* Raises {} as of version: 1.8\n'
104+
.format(ExpiredDeprecationError))
109105
func = dec('foo', '1.2', '1.8')(func_no_doc)
110106
with pytest.raises(ExpiredDeprecationError):
111107
func()
112108
assert (func.__doc__ ==
113-
'foo\n\n* deprecated from version: 1.2\n'
114-
'* Raises {} as of version: 1.8\n'
115-
.format(ExpiredDeprecationError))
109+
'foo\n\n* deprecated from version: 1.2\n'
110+
'* Raises {} as of version: 1.8\n'
111+
.format(ExpiredDeprecationError))
116112
func = dec('foo', '1.2', '1.8')(func_doc_long)
117113
assert (func.__doc__ ==
118-
'A docstring\n \n foo\n \n'
119-
' * deprecated from version: 1.2\n'
120-
' * Raises {} as of version: 1.8\n \n'
121-
' Some text\n'
122-
.format(ExpiredDeprecationError))
114+
'A docstring\n \n foo\n \n'
115+
' * deprecated from version: 1.2\n'
116+
' * Raises {} as of version: 1.8\n \n'
117+
' Some text\n'
118+
.format(ExpiredDeprecationError))
123119
with pytest.raises(ExpiredDeprecationError):
124120
func()
125121

nibabel/tests/test_ecat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from numpy.testing import assert_array_equal, assert_array_almost_equal
2323

24-
from ..testing_pytest import data_path, suppress_warnings, clear_and_catch_warnings
24+
from ..testing_pytest import data_path, suppress_warnings
2525
from ..tmpdirs import InTemporaryDirectory
2626

2727
from .test_wrapstruct import _TestWrapStructBase
@@ -271,8 +271,7 @@ def test_mlist_regression(self):
271271

272272
def test_from_filespec_deprecation():
273273
# Check from_filespec raises Deprecation
274-
with clear_and_catch_warnings() as w:
275-
warnings.simplefilter('always', DeprecationWarning)
274+
with pytest.deprecated_call() as w:
276275
# No warning for standard load
277276
img_loaded = EcatImage.load(ecat_file)
278277
assert len(w) == 0

nibabel/tests/test_nifti1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,10 +1131,10 @@ def test_extension_basics():
11311131
def test_ext_eq():
11321132
ext = Nifti1Extension('comment', '123')
11331133
assert ext == ext
1134-
assert ext == ext
1134+
assert not ext != ext
11351135
ext2 = Nifti1Extension('comment', '124')
11361136
assert ext != ext2
1137-
assert ext != ext2
1137+
assert not ext == ext2
11381138

11391139

11401140
def test_extension_codes():
@@ -1148,7 +1148,7 @@ def test_extension_list():
11481148
assert ext_c0 == ext_c1
11491149
ext = Nifti1Extension('comment', '123')
11501150
ext_c1.append(ext)
1151-
assert ext_c0 != ext_c1
1151+
assert not ext_c0 == ext_c1
11521152
ext_c0.append(ext)
11531153
assert ext_c0 == ext_c1
11541154

nibabel/tests/test_spatialimages.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ def test_get_data(self):
379379
img[0, 0, 0]
380380
# Make sure the right message gets raised:
381381
assert (str(exception_manager.value) ==
382-
"Cannot slice image objects; consider using "
383-
"`img.slicer[slice]` to generate a sliced image (see "
384-
"documentation for caveats) or slicing image array data "
385-
"with `img.dataobj[slice]` or `img.get_fdata()[slice]`")
382+
"Cannot slice image objects; consider using "
383+
"`img.slicer[slice]` to generate a sliced image (see "
384+
"documentation for caveats) or slicing image array data "
385+
"with `img.dataobj[slice]` or `img.get_fdata()[slice]`")
386386
assert in_data is img.dataobj
387387
with pytest.deprecated_call():
388388
out_data = img.get_data()
@@ -648,7 +648,10 @@ def test_load_mmap(self):
648648

649649

650650
def test_header_deprecated():
651-
with pytest.deprecated_call():
651+
with pytest.deprecated_call() as w:
652652
class MyHeader(Header):
653653
pass
654-
MyHeader()
654+
655+
assert len(w) == 0
656+
MyHeader()
657+
assert len(w) == 1

nibabel/tests/test_spm99analyze.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def test_origin_checks(self):
146146
fhdr, message, raiser = self.log_chk(hdr, 20)
147147
assert fhdr == hdr
148148
assert (message == 'very large origin values '
149-
'relative to dims; leaving as set, '
150-
'ignoring for affine')
149+
'relative to dims; leaving as set, '
150+
'ignoring for affine')
151151
pytest.raises(*raiser)
152152
# diagnose binary block
153153
dxer = self.header_class.diagnose_binaryblock

nibabel/tests/test_volumeutils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
assert_array_equal)
5858
import pytest
5959

60-
from ..testing_pytest import (assert_dt_equal, assert_allclose_safely,
61-
suppress_warnings, clear_and_catch_warnings)
60+
from ..testing_pytest import assert_dt_equal, assert_allclose_safely, suppress_warnings
6261

6362
#: convenience variables for numpy types
6463
FLOAT_TYPES = np.sctypes['float']
@@ -1019,8 +1018,7 @@ def test_fname_ext_ul_case():
10191018
def test_allopen():
10201019
# This import into volumeutils is for compatibility. The code is the
10211020
# ``openers`` module.
1022-
with clear_and_catch_warnings() as w:
1023-
warnings.filterwarnings('once', category=DeprecationWarning)
1021+
with pytest.deprecated_call() as w:
10241022
# Test default mode is 'rb'
10251023
fobj = allopen(__file__)
10261024
# Check we got the deprecation warning

0 commit comments

Comments
 (0)