From 813671318edbca75b6bd0de3acde4ce555d026a2 Mon Sep 17 00:00:00 2001 From: Gregory Lee Date: Wed, 23 Jun 2021 12:42:43 -0400 Subject: [PATCH] minor docstring fixes add assert statements to test_capabilities --- zarr/hierarchy.py | 2 +- zarr/storage.py | 28 ++++++++++++++-------------- zarr/tests/test_storage.py | 11 +++++------ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/zarr/hierarchy.py b/zarr/hierarchy.py index 11717e572b..fc64c1cf96 100644 --- a/zarr/hierarchy.py +++ b/zarr/hierarchy.py @@ -254,7 +254,7 @@ def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): - """If the underlying Store should always heave a ``close`` method, call it.""" + """Call the close method of the underlying Store.""" self.store.close() def info_items(self): diff --git a/zarr/storage.py b/zarr/storage.py index 2364d2bc2e..01dd9a0bde 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -82,8 +82,8 @@ class Store(MutableMapping): """Base class for stores implementation. - - Provide a number of default method as well as other typing guaranties for mypy. + Provide a number of default method as well as other typing guaranties for + mypy. Stores cannot be mutable mapping as they do have a couple of other requirements that would break Liskov substitution principle (stores only @@ -96,7 +96,7 @@ class Store(MutableMapping): Stores can be used as context manager to make sure they close on exit. - .. added: 2.5.0 + .. added: 2.9.0 """ @@ -135,7 +135,7 @@ def listdir(self, path: str = "") -> List[str]: def rename(self, src_path: str, dst_path: str) -> None: if not self.is_erasable(): raise NotImplementedError( - f'{type(self)} is not erasable, cannot call "rmdir"' + f'{type(self)} is not erasable, cannot call "rename"' ) # pragma: no cover _rename_from_keys(self, src_path, dst_path) @@ -154,9 +154,9 @@ def close(self) -> None: @staticmethod def _ensure_store(store): """ - We want to make sure internally that zarr storage are internally always - a class with a specific interface derived from Store, which is slightly - different than mutable mapping. + We want to make sure internally that zarr stores are always a class + with a specific interface derived from ``Store``, which is slightly + different than ``MutableMapping``. We'll do this conversion in a few places automatically """ @@ -182,8 +182,8 @@ def _ensure_store(store): return KVStore(store) raise ValueError( - "Starting with Zarr X.y.z, stores must be subclasses of Store, if " - "you store expose the MutableMapping interface wrap them in " + "Starting with Zarr 2.9.0, stores must be subclasses of Store, if " + "your store exposes the MutableMapping interface wrap it in " f"Zarr.storage.KVStore. Got {store}" ) @@ -281,8 +281,8 @@ def listdir(store: Store, path: Path = None): else: # slow version, iterate through all keys warnings.warn( - "Store {store} has not `listdir` method. From zarr 2.5 you may want" - "to inherit from `Store`.".format(store=store), + f"Store {store} has no `listdir` method. From zarr 2.9 onwards " + "may want to inherit from `Store`.", stacklevel=2, ) return _listdir_from_keys(store, path) @@ -641,10 +641,10 @@ def _dict_store_keys(d: Dict, prefix="", cls=dict): class KVStore(Store): """ - This provide an default implementation of a store interface around - a mutable mapping, to avoid having to test stores for presence of methods + This provides a default implementation of a store interface around + a mutable mapping, to avoid having to test stores for presence of methods. - This, for most method should just be a pass-through to the underlying KV + This, for most methods should just be a pass-through to the underlying KV store which is likely to expose a MuttableMapping interface, """ diff --git a/zarr/tests/test_storage.py b/zarr/tests/test_storage.py index 84305f9234..0d920c1293 100644 --- a/zarr/tests/test_storage.py +++ b/zarr/tests/test_storage.py @@ -68,11 +68,10 @@ class InvalidStore: def test_capabilities(): s = KVStore(dict()) - s.is_readable() - s.is_listable() - s.is_erasable() - s.is_writeable() - + assert s.is_readable() + assert s.is_listable() + assert s.is_erasable() + assert s.is_writeable() def test_getsize_non_implemented(): assert getsize(object()) == -1 @@ -90,7 +89,7 @@ def test_coverage_rename(): def test_deprecated_listdir_nosotre(): store = dict() - with pytest.warns(UserWarning, match="has not `listdir`"): + with pytest.warns(UserWarning, match="has no `listdir`"): listdir(store)