<s> """<STR_LIT>""" <EOL> import os <EOL> import numpy as np <EOL> from holoviews import Image , Layout <EOL> from holoviews . core . io import Serializer , Pickler , Unpickler , Deserializer <EOL> from holoviews . element . comparison import ComparisonTestCase <EOL> class TestSerialization ( ComparisonTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . image1 = Image ( np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:4> , <NUM_LIT:5> ] ] ) ) <EOL> self . image2 = Image ( np . array ( [ [ <NUM_LIT:5> , <NUM_LIT:4> ] , [ <NUM_LIT:3> , <NUM_LIT:2> ] ] ) ) <EOL> def tearDown ( self ) : <EOL> for f in os . listdir ( '<STR_LIT:.>' ) : <EOL> if f . endswith ( '<STR_LIT>' ) : <EOL> os . remove ( f ) <EOL> def test_serializer_save ( self ) : <EOL> Serializer . save ( self . image1 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> def test_serializer_save_no_file_extension ( self ) : <EOL> Serializer . save ( self . image1 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> if '<STR_LIT>' not in os . listdir ( '<STR_LIT:.>' ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> def test_serializer_save_and_load_data_1 ( self ) : <EOL> Serializer . save ( self . image1 , '<STR_LIT>' ) <EOL> loaded = Deserializer . load ( '<STR_LIT>' ) <EOL> self . assertEqual ( loaded , self . image1 ) <EOL> def test_serializer_save_and_load_data_2 ( self ) : <EOL> Serializer . save ( self . image2 , '<STR_LIT>' ) <EOL> loaded = Deserializer . load ( '<STR_LIT>' ) <EOL> self . assertEqual ( loaded , self . image2 ) <EOL> def test_serializer_save_and_load_key ( self ) : <EOL> input_key = { '<STR_LIT>' : '<STR_LIT>' } <EOL> Serializer . save ( self . image1 , '<STR_LIT>' , key = input_key ) <EOL> key = Deserializer . key ( '<STR_LIT>' ) <EOL> self . assertEqual ( key , input_key ) <EOL> def test_serializer_save_and_load_info ( self ) : <EOL> input_info = { '<STR_LIT:info>' : '<STR_LIT>' } <EOL> Serializer . save ( self . image1 , '<STR_LIT>' , info = input_info ) <EOL> info = Deserializer . info ( '<STR_LIT>' ) <EOL> self . assertEqual ( info [ '<STR_LIT:info>' ] , input_info [ '<STR_LIT:info>' ] ) <EOL> def test_serialize_deserialize_1 ( self ) : <EOL> data , _ = Serializer ( self . image1 ) <EOL> obj = Deserializer ( data ) <EOL> self . assertEqual ( obj , self . image1 ) <EOL> def test_serialize_deserialize_2 ( self ) : <EOL> data , _ = Serializer ( self . image2 ) <EOL> obj = Deserializer ( data ) <EOL> self . assertEqual ( obj , self . image2 ) <EOL> class TestBasicPickler ( ComparisonTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . image1 = Image ( np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:4> , <NUM_LIT:5> ] ] ) ) <EOL> self . image2 = Image ( np . array ( [ [ <NUM_LIT:5> , <NUM_LIT:4> ] , [ <NUM_LIT:3> , <NUM_LIT:2> ] ] ) ) <EOL> def tearDown ( self ) : <EOL> for f in os . listdir ( '<STR_LIT:.>' ) : <EOL> if f . endswith ( '<STR_LIT>' ) : <EOL> os . remove ( f ) <EOL> def test_pickler_save ( self ) : <EOL> Pickler . save ( self . image1 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> def test_pickler_save_no_file_extension ( self ) : <EOL> Pickler . save ( self . image1 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> if '<STR_LIT>' not in os . listdir ( '<STR_LIT:.>' ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> def test_pickler_save_and_load_data_1 ( self ) : <EOL> Pickler . save ( self . image1 , '<STR_LIT>' ) <EOL> loaded = Unpickler . load ( '<STR_LIT>' ) <EOL> self . assertEqual ( loaded , self . image1 ) <EOL> def test_pickler_save_and_load_data_2 ( self ) : <EOL> Pickler . save ( self . image2 , '<STR_LIT>' ) <EOL> loaded = Unpickler . load ( '<STR_LIT>' ) <EOL> self . assertEqual ( loaded , self . image2 ) <EOL> def test_pickler_save_and_load_key ( self ) : <EOL> input_key = { '<STR_LIT>' : '<STR_LIT>' } <EOL> Pickler . save ( self . image1 , '<STR_LIT>' , key = input_key ) <EOL> key = Unpickler . key ( '<STR_LIT>' ) <EOL> self . assertEqual ( key , input_key ) <EOL> def test_pickler_save_and_load_info ( self ) : <EOL> input_info = { '<STR_LIT:info>' : '<STR_LIT>' } <EOL> Pickler . save ( self . image1 , '<STR_LIT>' , info = input_info ) <EOL> info = Unpickler . info ( '<STR_LIT>' ) <EOL> self . assertEqual ( info [ '<STR_LIT:info>' ] , input_info [ '<STR_LIT:info>' ] ) <EOL> def test_serialize_deserialize_1 ( self ) : <EOL> data , _ = Pickler ( self . image1 ) <EOL> obj = Unpickler ( data ) <EOL> self . assertEqual ( obj , self . image1 ) <EOL> def test_serialize_deserialize_2 ( self ) : <EOL> data , _ = Pickler ( self . image2 ) <EOL> obj = Unpickler ( data ) <EOL> self . assertEqual ( obj , self . image2 ) <EOL> class TestPicklerAdvanced ( ComparisonTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . image1 = Image ( np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:4> , <NUM_LIT:5> ] ] ) ) <EOL> self . image2 = Image ( np . array ( [ [ <NUM_LIT:5> , <NUM_LIT:4> ] , [ <NUM_LIT:3> , <NUM_LIT:2> ] ] ) ) <EOL> def tearDown ( self ) : <EOL> for f in os . listdir ( '<STR_LIT:.>' ) : <EOL> if f . endswith ( '<STR_LIT>' ) : <EOL> os . remove ( f ) <EOL> def test_pickler_save_layout ( self ) : <EOL> Pickler . save ( self . image1 + self . image2 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> def test_pickler_save_load_layout ( self ) : <EOL> Pickler . save ( self . image1 + self . image2 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> loaded = Unpickler . load ( '<STR_LIT>' ) <EOL> self . assertEqual ( loaded , self . image1 + self . image2 ) <EOL> def test_pickler_save_load_layout_entries ( self ) : <EOL> Pickler . save ( self . image1 + self . image2 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> entries = Unpickler . entries ( '<STR_LIT>' ) <EOL> self . assertEqual ( entries , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_pickler_save_load_layout_entry1 ( self ) : <EOL> Pickler . save ( self . image1 + self . image2 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> entries = Unpickler . entries ( '<STR_LIT>' ) <EOL> assert ( '<STR_LIT>' in entries ) , "<STR_LIT>" <EOL> loaded = Unpickler . load ( '<STR_LIT>' , <EOL> entries = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( loaded , self . image1 ) <EOL> def test_pickler_save_load_layout_entry2 ( self ) : <EOL> Pickler . save ( self . image1 + self . image2 , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> entries = Unpickler . entries ( '<STR_LIT>' ) <EOL> assert ( '<STR_LIT>' in entries ) , "<STR_LIT>" <EOL> loaded = Unpickler . load ( '<STR_LIT>' , <EOL> entries = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( loaded , self . image2 ) <EOL> def test_pickler_save_load_single_layout ( self ) : <EOL> single_layout = Layout . from_values ( [ self . image1 ] ) <EOL> Pickler . save ( single_layout , '<STR_LIT>' , <EOL> info = { '<STR_LIT:info>' : '<STR_LIT>' } , key = { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> entries = Unpickler . entries ( '<STR_LIT>' ) <EOL> self . assertEqual ( entries , [ '<STR_LIT>' ] ) <EOL> loaded = Unpickler . load ( '<STR_LIT>' , <EOL> entries = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( single_layout , loaded ) </s>
