Skip to content

Commit 1f6a608

Browse files
committed
RF: Avoid validation when testing CIFTI saving
1 parent b401b14 commit 1f6a608

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

nibabel/cifti2/tests/test_cifti2.py

+15
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,18 @@ def make_imaker(self, arr, header=None, ni_header=None):
427427
)
428428
header.matrix.append(mim)
429429
return lambda: self.image_maker(arr.copy(), header, ni_header)
430+
431+
def validate_filenames(self, imaker, params, validate=False):
432+
super().validate_filenames(imaker, params, validate=validate)
433+
434+
def validate_mmap_parameter(self, imaker, params, validate=False):
435+
super().validate_mmap_parameter(imaker, params, validate=validate)
436+
437+
def validate_to_bytes(self, imaker, params, validate=False):
438+
super().validate_to_bytes(imaker, params, validate=validate)
439+
440+
def validate_from_bytes(self, imaker, params, validate=False):
441+
super().validate_from_bytes(imaker, params, validate=validate)
442+
443+
def validate_to_from_bytes(self, imaker, params, validate=False):
444+
super().validate_to_from_bytes(imaker, params, validate=validate)

nibabel/cifti2/tests/test_cifti2io_axes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def check_rewrite(arr, axes, extension='.nii'):
9191
custom extension to use
9292
"""
9393
(fd, name) = tempfile.mkstemp(extension)
94-
cifti2.Cifti2Image(arr, header=axes).to_filename(name)
94+
cifti2.Cifti2Image(arr, header=axes).to_filename(name, validate=False)
9595
img = nib.load(name)
9696
arr2 = img.get_fdata()
9797
assert np.allclose(arr, arr2)

nibabel/cifti2/tests/test_new_cifti2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def test_plabel():
406406
img = ci.Cifti2Image(data, hdr)
407407

408408
with InTemporaryDirectory():
409-
ci.save(img, 'test.plabel.nii')
409+
ci.save(img, 'test.plabel.nii', validate=False)
410410
img2 = ci.load('test.plabel.nii')
411411
assert img.nifti_header.get_intent()[0] == 'ConnUnknown'
412412
assert isinstance(img2, ci.Cifti2Image)

nibabel/tests/test_image_api.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def validate_header_deprecated(self, imaker, params):
123123
hdr = img.get_header()
124124
assert hdr is img.header
125125

126-
def validate_filenames(self, imaker, params):
126+
def validate_filenames(self, imaker, params, **kwargs):
127127
# Validate the filename, file_map interface
128128

129129
if not self.can_save:
@@ -160,7 +160,7 @@ def validate_filenames(self, imaker, params):
160160
warnings.filterwarnings('error',
161161
category=DeprecationWarning,
162162
module=r"nibabel.*")
163-
img.to_filename(path)
163+
img.to_filename(path, **kwargs)
164164
rt_img = img.__class__.from_filename(path)
165165
assert_array_equal(img.shape, rt_img.shape)
166166
assert_almost_equal(img.get_fdata(), rt_img.get_fdata())
@@ -456,7 +456,7 @@ def validate_shape_deprecated(self, imaker, params):
456456
with pytest.raises(ExpiredDeprecationError):
457457
img.get_shape()
458458

459-
def validate_mmap_parameter(self, imaker, params):
459+
def validate_mmap_parameter(self, imaker, params, **kwargs):
460460
img = imaker()
461461
fname = img.get_filename()
462462
with InTemporaryDirectory():
@@ -468,7 +468,7 @@ def validate_mmap_parameter(self, imaker, params):
468468
if not img.rw or not img.valid_exts:
469469
return
470470
fname = 'image' + img.valid_exts[0]
471-
img.to_filename(fname)
471+
img.to_filename(fname, **kwargs)
472472
rt_img = img.__class__.from_filename(fname, mmap=True)
473473
assert_almost_equal(img.get_fdata(), rt_img.get_fdata())
474474
rt_img = img.__class__.from_filename(fname, mmap=False)
@@ -533,22 +533,22 @@ def validate_affine_deprecated(self, imaker, params):
533533

534534

535535
class SerializeMixin(object):
536-
def validate_to_bytes(self, imaker, params):
536+
def validate_to_bytes(self, imaker, params, **kwargs):
537537
img = imaker()
538538
serialized = img.to_bytes()
539539
with InTemporaryDirectory():
540540
fname = 'img' + self.standard_extension
541-
img.to_filename(fname)
541+
img.to_filename(fname, **kwargs)
542542
with open(fname, 'rb') as fobj:
543543
file_contents = fobj.read()
544544
assert serialized == file_contents
545545

546-
def validate_from_bytes(self, imaker, params):
546+
def validate_from_bytes(self, imaker, params, **kwargs):
547547
img = imaker()
548548
klass = getattr(self, 'klass', img.__class__)
549549
with InTemporaryDirectory():
550550
fname = 'img' + self.standard_extension
551-
img.to_filename(fname)
551+
img.to_filename(fname, **kwargs)
552552

553553
all_images = list(getattr(self, 'example_images', [])) + [{'fname': fname}]
554554
for img_params in all_images:
@@ -561,12 +561,12 @@ def validate_from_bytes(self, imaker, params):
561561
del img_a
562562
del img_b
563563

564-
def validate_to_from_bytes(self, imaker, params):
564+
def validate_to_from_bytes(self, imaker, params, **kwargs):
565565
img = imaker()
566566
klass = getattr(self, 'klass', img.__class__)
567567
with InTemporaryDirectory():
568568
fname = 'img' + self.standard_extension
569-
img.to_filename(fname)
569+
img.to_filename(fname, **kwargs)
570570

571571
all_images = list(getattr(self, 'example_images', [])) + [{'fname': fname}]
572572
for img_params in all_images:

0 commit comments

Comments
 (0)