File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 15
15
import os
16
16
import re
17
17
import logging
18
+ import pickle
18
19
19
20
import numpy as np
20
21
@@ -589,6 +590,24 @@ def test_header_updating(self):
589
590
img_back = img .from_file_map (img .file_map )
590
591
assert_array_equal (img_back .shape , (3 , 2 , 4 ))
591
592
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
+
592
611
593
612
def test_unsupported ():
594
613
# analyze does not support uint32
You can’t perform that action at this time.
0 commit comments