Skip to content

Commit e1da57c

Browse files
committed
TEST: Use standard syntax when possible
1 parent a411f33 commit e1da57c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

nibabel/tests/test_image_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def validate_header(self, imaker, params):
108108
hdr = img.header # we can fetch it
109109
# Read only
110110
with pytest.raises(AttributeError):
111-
setattr(img, 'header', hdr)
111+
img.header = hdr
112112

113113
def validate_header_deprecated(self, imaker, params):
114114
# Check deprecated header API
@@ -164,9 +164,9 @@ def validate_filenames(self, imaker, params):
164164
def validate_no_slicing(self, imaker, params):
165165
img = imaker()
166166
with pytest.raises(TypeError):
167-
img.__getitem__('string')
167+
img['string']
168168
with pytest.raises(TypeError):
169-
img.__getitem__(slice(None))
169+
img[:]
170170

171171
def validate_get_data_deprecated(self, imaker, params):
172172
# Check deprecated header API
@@ -231,10 +231,10 @@ def validate_data_interface(self, imaker, params):
231231
# dataobj is read only
232232
fake_data = np.zeros(img.shape).astype(img.get_data_dtype())
233233
with pytest.raises(AttributeError):
234-
setattr(img, 'dataobj', fake_data)
234+
img.dataobj = fake_data
235235
# So is in_memory
236236
with pytest.raises(AttributeError):
237-
setattr(img, 'in_memory', False)
237+
img.in_memory = False
238238

239239
def _check_proxy_interface(self, imaker, meth_name):
240240
# Parameters assert this is an array proxy
@@ -402,7 +402,7 @@ def validate_data_deprecated(self, imaker, params):
402402
# Check setting _data raises error
403403
fake_data = np.zeros(img.shape).astype(img.get_data_dtype())
404404
with pytest.raises(AttributeError):
405-
setattr(img, '_data', fake_data)
405+
img._data = fake_data
406406

407407
def validate_shape(self, imaker, params):
408408
# Validate shape
@@ -414,7 +414,7 @@ def validate_shape(self, imaker, params):
414414
assert img.shape == params['data'].shape
415415
# Read only
416416
with pytest.raises(AttributeError):
417-
setattr(img, 'shape', np.eye(4))
417+
img.shape = np.eye(4)
418418

419419
def validate_ndim(self, imaker, params):
420420
# Validate shape
@@ -426,7 +426,7 @@ def validate_ndim(self, imaker, params):
426426
assert img.ndim == params['data'].ndim
427427
# Read only
428428
with pytest.raises(AttributeError):
429-
setattr(img, 'ndim', 5)
429+
img.ndim = 5
430430

431431
def validate_shape_deprecated(self, imaker, params):
432432
# Check deprecated get_shape API
@@ -497,7 +497,7 @@ def validate_affine(self, imaker, params):
497497
assert img.affine[0, 0] == 1.5
498498
# Read only
499499
with pytest.raises(AttributeError):
500-
setattr(img, 'affine', np.eye(4))
500+
img.affine = np.eye(4)
501501

502502
def validate_affine_deprecated(self, imaker, params):
503503
# Check deprecated affine API

0 commit comments

Comments
 (0)