Skip to content

Commit 59f6db4

Browse files
committed
TEST: Check that serialization fails as expected for multi-part images
1 parent 895068d commit 59f6db4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

nibabel/tests/test_filebasedimages.py

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import warnings
66

77
import numpy as np
8+
import pytest
89

910
from ..filebasedimages import FileBasedHeader, FileBasedImage, SerializableImage
1011

@@ -127,3 +128,24 @@ def __init__(self, seq=None):
127128
hdr4 = H.from_header(None)
128129
assert isinstance(hdr4, H)
129130
assert hdr4.a_list == []
131+
132+
133+
class MultipartNumpyImage(FBNumpyImage):
134+
# We won't actually try to write these out, just need to test an edge case
135+
files_types = (('header', '.hdr'), ('image', '.npy'))
136+
137+
138+
class SerializableMPNumpyImage(MultipartNumpyImage, SerializableImage):
139+
pass
140+
141+
142+
def test_multifile_stream_failure():
143+
shape = (2, 3, 4)
144+
arr = np.arange(np.prod(shape), dtype=np.float32).reshape(shape)
145+
img = SerializableMPNumpyImage(arr)
146+
with pytest.raises(NotImplementedError):
147+
img.to_bytes()
148+
img = SerializableNumpyImage(arr)
149+
bstr = img.to_bytes()
150+
with pytest.raises(NotImplementedError):
151+
SerializableMPNumpyImage.from_bytes(bstr)

0 commit comments

Comments
 (0)