@@ -114,6 +114,74 @@ def test_to_b2z_and_reopen(populated_dict_store):
114114 assert np .all (dstore_read ["/nodeB" ][:] == np .arange (6 ))
115115
116116
117+ def test_to_b2z_from_readonly_b2d ():
118+ b2d_path = "test_to_b2z_from_readonly.b2d"
119+ b2z_path = "test_to_b2z_from_readonly.b2z"
120+
121+ if os .path .exists (b2d_path ):
122+ shutil .rmtree (b2d_path )
123+ if os .path .exists (b2z_path ):
124+ os .remove (b2z_path )
125+
126+ with DictStore (b2d_path , mode = "w" ) as dstore :
127+ dstore ["/nodeA" ] = np .arange (5 )
128+ dstore ["/nodeB" ] = np .arange (6 )
129+
130+ with DictStore (b2d_path , mode = "r" ) as dstore :
131+ packed = dstore .to_b2z (filename = b2z_path )
132+ assert packed .endswith (b2z_path )
133+
134+ with DictStore (b2z_path , mode = "r" ) as dstore :
135+ assert np .all (dstore ["/nodeA" ][:] == np .arange (5 ))
136+ assert np .all (dstore ["/nodeB" ][:] == np .arange (6 ))
137+
138+ shutil .rmtree (b2d_path )
139+ os .remove (b2z_path )
140+
141+
142+ def test_to_b2z_accepts_positional_filename ():
143+ b2d_path = "test_to_b2z_positional_filename.b2d"
144+ b2z_path = "test_to_b2z_positional_filename.b2z"
145+
146+ if os .path .exists (b2d_path ):
147+ shutil .rmtree (b2d_path )
148+ if os .path .exists (b2z_path ):
149+ os .remove (b2z_path )
150+
151+ with DictStore (b2d_path , mode = "w" ) as dstore :
152+ dstore ["/nodeA" ] = np .arange (5 )
153+
154+ with DictStore (b2d_path , mode = "r" ) as dstore :
155+ packed = dstore .to_b2z (b2z_path )
156+ assert packed .endswith (b2z_path )
157+
158+ with DictStore (b2z_path , mode = "r" ) as dstore :
159+ assert np .all (dstore ["/nodeA" ][:] == np .arange (5 ))
160+
161+ shutil .rmtree (b2d_path )
162+ os .remove (b2z_path )
163+
164+
165+ def test_to_b2z_from_readonly_b2z_raises ():
166+ b2z_path = "test_to_b2z_readonly_zip.b2z"
167+ out_path = "test_to_b2z_readonly_zip_out.b2z"
168+
169+ for path in (b2z_path , out_path ):
170+ if os .path .exists (path ):
171+ os .remove (path )
172+
173+ with DictStore (b2z_path , mode = "w" ) as dstore :
174+ dstore ["/nodeA" ] = np .arange (5 )
175+
176+ with (
177+ DictStore (b2z_path , mode = "r" ) as dstore ,
178+ pytest .raises (ValueError , match = r"\.b2z DictStore opened in read mode" ),
179+ ):
180+ dstore .to_b2z (filename = out_path )
181+
182+ os .remove (b2z_path )
183+
184+
117185def test_map_tree_precedence (populated_dict_store ):
118186 dstore , path = populated_dict_store
119187 # Create external file and add to dstore
0 commit comments