Skip to content

Commit 78babe9

Browse files
committed
TST - add test that analyze type images pickle
Thanks to Gael for pointing out the problem. Fixes gh-77.
1 parent 1eb88d1 commit 78babe9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

nibabel/tests/test_analyze.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import re
1717
import logging
18+
import pickle
1819

1920
import numpy as np
2021

@@ -589,6 +590,24 @@ def test_header_updating(self):
589590
img_back = img.from_file_map(img.file_map)
590591
assert_array_equal(img_back.shape, (3, 2, 4))
591592

593+
def test_pickle(self):
594+
# Test that images pickle
595+
# Image that is not proxied can pickle
596+
img_klass = self.image_class
597+
img = img_klass(np.zeros((2,3,4)), None)
598+
img_str = pickle.dumps(img)
599+
img2 = pickle.loads(img_str)
600+
assert_array_equal(img.get_data(), img2.get_data())
601+
assert_equal(img.get_header(), img2.get_header())
602+
# Save / reload using bytes IO objects
603+
for key, value in img.file_map.items():
604+
value.fileobj = BytesIO()
605+
img.to_file_map()
606+
img_prox = img.from_file_map(img.file_map)
607+
img_str = pickle.dumps(img_prox)
608+
img2_prox = pickle.loads(img_str)
609+
assert_array_equal(img.get_data(), img2_prox.get_data())
610+
592611

593612
def test_unsupported():
594613
# analyze does not support uint32

0 commit comments

Comments
 (0)