1616import zarr
1717from zarr .abc .store import AccessMode , Store
1818from zarr .core .buffer import BufferPrototype , cpu , default_buffer_prototype
19- from zarr .store import ZipStore
19+ from zarr .store import LocalStore , ZipStore
2020from zarr .testing .strategies import key_ranges , keys
2121
2222
@@ -183,9 +183,13 @@ def clear(self) -> None:
183183 self .store .clear ()
184184 self .model .clear ()
185185
186+ assert self .store .empty ()
187+
186188 assert len (self .model .keys ()) == len (list (self .store .list ())) == 0
187189
188190 @rule ()
191+ # Local store can be non-empty when there are subdirectories but no files
192+ @precondition (lambda self : not isinstance (self .store .store , LocalStore ))
189193 def empty (self ) -> None :
190194 note ("(empty)" )
191195
@@ -201,9 +205,9 @@ def exists(self, key: str) -> None:
201205 @invariant ()
202206 def check_paths_equal (self ) -> None :
203207 note ("Checking that paths are equal" )
204- paths = list (self .store .list ())
208+ paths = sorted (self .store .list ())
205209
206- assert list (self .model .keys ()) == paths
210+ assert sorted (self .model .keys ()) == paths
207211
208212 @invariant ()
209213 def check_vals_equal (self ) -> None :
@@ -220,16 +224,18 @@ def check_num_keys_equal(self) -> None:
220224
221225 @invariant ()
222226 def check_keys (self ) -> None :
227+ # For local store, this can be empty if there are no files,
228+ # but there are subfolders that weren't cleared.
223229 keys = list (self .store .list ())
224230
225- if len (keys ) == 0 :
226- assert self .store .empty () is True
231+ # if len(keys) == 0:
232+ # assert self.store.empty() is True
227233
228- elif len (keys ) != 0 :
229- assert self .store .empty () is False
234+ # elif len(keys) != 0:
235+ # assert self.store.empty() is False
230236
231- for key in keys :
232- assert self .store .exists (key ) is True
237+ for key in keys :
238+ assert self .store .exists (key ) is True
233239 note ("checking keys / exists / empty" )
234240
235241
@@ -239,4 +245,6 @@ def mk_test_instance_sync():
239245
240246 if isinstance (sync_store , ZipStore ):
241247 pytest .skip (reason = "ZipStore does not support delete" )
242- run_state_machine_as_test (mk_test_instance_sync , settings = Settings (report_multiple_bugs = False ))
248+ if isinstance (sync_store , LocalStore ):
249+ pytest .skip (reason = "This test does not handle subdirectories" )
250+ run_state_machine_as_test (mk_test_instance_sync , settings = Settings (report_multiple_bugs = True ))
0 commit comments