Skip to content

Commit 2eab490

Browse files
committed
RF: Avoid validation when testing CIFTI saving
1 parent b55a363 commit 2eab490

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
@@ -426,3 +426,18 @@ def make_imaker(self, arr, header=None, ni_header=None):
426426
)
427427
header.matrix.append(mim)
428428
return lambda: self.image_maker(arr.copy(), header, ni_header)
429+
430+
def validate_filenames(self, imaker, params, validate=False):
431+
super().validate_filenames(imaker, params, validate=validate)
432+
433+
def validate_mmap_parameter(self, imaker, params, validate=False):
434+
super().validate_mmap_parameter(imaker, params, validate=validate)
435+
436+
def validate_to_bytes(self, imaker, params, validate=False):
437+
super().validate_to_bytes(imaker, params, validate=validate)
438+
439+
def validate_from_bytes(self, imaker, params, validate=False):
440+
super().validate_from_bytes(imaker, params, validate=validate)
441+
442+
def validate_to_from_bytes(self, imaker, params, validate=False):
443+
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
@@ -118,7 +118,7 @@ def validate_header_deprecated(self, imaker, params):
118118
hdr = img.get_header()
119119
assert hdr is img.header
120120

121-
def validate_filenames(self, imaker, params):
121+
def validate_filenames(self, imaker, params, **kwargs):
122122
# Validate the filename, file_map interface
123123

124124
if not self.can_save:
@@ -155,7 +155,7 @@ def validate_filenames(self, imaker, params):
155155
warnings.filterwarnings('error',
156156
category=DeprecationWarning,
157157
module=r"nibabel.*")
158-
img.to_filename(path)
158+
img.to_filename(path, **kwargs)
159159
rt_img = img.__class__.from_filename(path)
160160
assert_array_equal(img.shape, rt_img.shape)
161161
assert_almost_equal(img.get_fdata(), rt_img.get_fdata())
@@ -433,7 +433,7 @@ def validate_shape_deprecated(self, imaker, params):
433433
with pytest.raises(ExpiredDeprecationError):
434434
img.get_shape()
435435

436-
def validate_mmap_parameter(self, imaker, params):
436+
def validate_mmap_parameter(self, imaker, params, **kwargs):
437437
img = imaker()
438438
fname = img.get_filename()
439439
with InTemporaryDirectory():
@@ -445,7 +445,7 @@ def validate_mmap_parameter(self, imaker, params):
445445
if not img.rw or not img.valid_exts:
446446
return
447447
fname = 'image' + img.valid_exts[0]
448-
img.to_filename(fname)
448+
img.to_filename(fname, **kwargs)
449449
rt_img = img.__class__.from_filename(fname, mmap=True)
450450
assert_almost_equal(img.get_fdata(), rt_img.get_fdata())
451451
rt_img = img.__class__.from_filename(fname, mmap=False)
@@ -510,22 +510,22 @@ def validate_affine_deprecated(self, imaker, params):
510510

511511

512512
class SerializeMixin(object):
513-
def validate_to_bytes(self, imaker, params):
513+
def validate_to_bytes(self, imaker, params, **kwargs):
514514
img = imaker()
515515
serialized = img.to_bytes()
516516
with InTemporaryDirectory():
517517
fname = 'img' + self.standard_extension
518-
img.to_filename(fname)
518+
img.to_filename(fname, **kwargs)
519519
with open(fname, 'rb') as fobj:
520520
file_contents = fobj.read()
521521
assert serialized == file_contents
522522

523-
def validate_from_bytes(self, imaker, params):
523+
def validate_from_bytes(self, imaker, params, **kwargs):
524524
img = imaker()
525525
klass = getattr(self, 'klass', img.__class__)
526526
with InTemporaryDirectory():
527527
fname = 'img' + self.standard_extension
528-
img.to_filename(fname)
528+
img.to_filename(fname, **kwargs)
529529

530530
all_images = list(getattr(self, 'example_images', [])) + [{'fname': fname}]
531531
for img_params in all_images:
@@ -538,12 +538,12 @@ def validate_from_bytes(self, imaker, params):
538538
del img_a
539539
del img_b
540540

541-
def validate_to_from_bytes(self, imaker, params):
541+
def validate_to_from_bytes(self, imaker, params, **kwargs):
542542
img = imaker()
543543
klass = getattr(self, 'klass', img.__class__)
544544
with InTemporaryDirectory():
545545
fname = 'img' + self.standard_extension
546-
img.to_filename(fname)
546+
img.to_filename(fname, **kwargs)
547547

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

0 commit comments

Comments
 (0)