Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't import from tests #1601

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ Release notes
# to document your changes. On releases it will be
# re-indented so that it does not show up in the notes.

.. _unreleased(v3):

Unreleased (v3)
---------------

Maintenance
~~~~~~~~~~~

* Remedy a situation where ``zarr-python`` was importing ``DummyStorageTransformer`` from the test suite.
The dependency relationship is now reversed: the test suite imports this class from ``zarr-python``.
By :user:`Davis Bennett <d-v-b>` :issue:`1601`.

.. _unreleased:

Unreleased
----------
Unreleased (v2)
---------------

Docs
~~~~
Expand Down Expand Up @@ -61,7 +73,6 @@ Maintenance
* Remove ``sphinx-rtd-theme`` dependency from ``pyproject.toml``.
By :user:`Sanket Verma <MSanKeys963>` :issue:`1563`.


.. _release_2.16.1:

2.16.1
Expand Down
16 changes: 16 additions & 0 deletions zarr/_storage/v3_storage_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def create_empty(cls, store: "ShardingStorageTransformer"):
)


class DummyStorageTransfomer(StorageTransformer):
"""For testing purposes. This class was previously defined in the test suite and imported
into Zarr, but now it has been moved here and the test suite will import it like any other part
of the Zarr library."""

TEST_CONSTANT = "test1234"

extension_uri = "https://purl.org/zarr/spec/storage_transformers/dummy/1.0"
valid_types = ["dummy_type"]

def __init__(self, _type, test_value) -> None:
super().__init__(_type)
assert test_value == self.TEST_CONSTANT
self.test_value = test_value


class ShardingStorageTransformer(StorageTransformer): # lgtm[py/missing-equals]
"""Implements sharding as a storage transformer, as described in the spec:
https://zarr-specs.readthedocs.io/en/latest/extensions/storage-transformers/sharding/v1.0.html
Expand Down
6 changes: 4 additions & 2 deletions zarr/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,10 @@ def _encode_storage_transformer_metadata(

@classmethod
def _decode_storage_transformer_metadata(cls, meta: Mapping) -> "StorageTransformer":
from zarr.tests.test_storage_v3 import DummyStorageTransfomer
from zarr._storage.v3_storage_transformers import ShardingStorageTransformer
from zarr._storage.v3_storage_transformers import (
ShardingStorageTransformer,
DummyStorageTransfomer,
)

# This might be changed to a proper registry in the future
KNOWN_STORAGE_TRANSFORMERS = [DummyStorageTransfomer, ShardingStorageTransformer]
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from zarr.attrs import Attributes
from zarr.storage import KVStore, DirectoryStore
from zarr._storage.v3 import KVStoreV3
from zarr.tests.util import CountingDict, CountingDictV3
from .util import CountingDict, CountingDictV3
from zarr.hierarchy import group


Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
MemoryStoreV3,
SQLiteStoreV3,
)
from zarr.tests.util import have_fsspec
from .util import have_fsspec

_VERSIONS = (2, 3) if v3_api_available else (2,)

Expand Down
10 changes: 7 additions & 3 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
BaseStore,
v3_api_available,
)
from .._storage.v3_storage_transformers import ShardingStorageTransformer, v3_sharding_available
from .._storage.v3_storage_transformers import (
DummyStorageTransfomer,
ShardingStorageTransformer,
v3_sharding_available,
)
from zarr.core import Array
from zarr.errors import ArrayNotFoundError, ContainsGroupError
from zarr.meta import json_loads
Expand Down Expand Up @@ -70,9 +74,9 @@
SQLiteStoreV3,
StoreV3,
)
from zarr.tests.test_storage_v3 import DummyStorageTransfomer

from zarr.util import buffer_size
from zarr.tests.util import abs_container, skip_test_env_var, have_fsspec, mktemp
from .util import abs_container, skip_test_env_var, have_fsspec, mktemp

# noinspection PyMethodMayBeStatic

Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from numpy.testing import assert_array_equal

from zarr._storage.store import DEFAULT_ZARR_VERSION
from zarr._storage.v3_storage_transformers import DummyStorageTransfomer
from zarr.codecs import Zlib
from zarr.core import Array
from zarr.creation import (
Expand All @@ -30,8 +31,7 @@
from zarr._storage.store import v3_api_available
from zarr._storage.v3 import DirectoryStoreV3, KVStoreV3
from zarr.sync import ThreadSynchronizer
from zarr.tests.test_storage_v3 import DummyStorageTransfomer
from zarr.tests.util import mktemp, have_fsspec
from .util import mktemp, have_fsspec


_VERSIONS = (None, 2, 3) if v3_api_available else (None, 2)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_dim_separator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import zarr
from zarr.core import Array
from zarr.storage import DirectoryStore, NestedDirectoryStore, FSStore
from zarr.tests.util import have_fsspec
from .util import have_fsspec


needs_fsspec = pytest.mark.skipif(not have_fsspec, reason="needs fsspec")
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
LRUStoreCacheV3,
)
from zarr.util import InfoReporter, buffer_size
from zarr.tests.util import skip_test_env_var, have_fsspec, abs_container, mktemp
from .util import skip_test_env_var, have_fsspec, abs_container, mktemp


_VERSIONS = (2, 3) if v3_api_available else (2,)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PartialChunkIterator,
)

from zarr.tests.util import CountingDict
from .util import CountingDict


def test_normalize_integer_selection():
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_n5.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import json
import atexit

from zarr.tests.util import have_fsspec
from .util import have_fsspec


def test_make_n5_chunk_wrapper():
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
)
from zarr.storage import FSStore, rename, listdir
from zarr._storage.v3 import KVStoreV3
from zarr.tests.util import CountingDict, have_fsspec, skip_test_env_var, abs_container, mktemp
from .util import CountingDict, have_fsspec, skip_test_env_var, abs_container, mktemp
from zarr.util import ConstantMap, json_dumps


Expand Down
20 changes: 6 additions & 14 deletions zarr/tests/test_storage_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

import zarr
from zarr._storage.store import _get_hierarchy_metadata, v3_api_available, StorageTransformer
from zarr._storage.v3_storage_transformers import ShardingStorageTransformer, v3_sharding_available
from zarr._storage.v3_storage_transformers import (
DummyStorageTransfomer,
ShardingStorageTransformer,
v3_sharding_available,
)
from zarr.core import Array
from zarr.meta import _default_entry_point_metadata_v3
from zarr.storage import (
Expand Down Expand Up @@ -40,7 +44,7 @@
StoreV3,
ZipStoreV3,
)
from zarr.tests.util import CountingDictV3, have_fsspec, skip_test_env_var, mktemp
from .util import CountingDictV3, have_fsspec, skip_test_env_var, mktemp

# pytest will fail to run if the following fixtures aren't imported here
from .test_storage import StoreTests as _StoreTests
Expand Down Expand Up @@ -108,18 +112,6 @@ def keys(self):
"""keys"""


class DummyStorageTransfomer(StorageTransformer):
TEST_CONSTANT = "test1234"

extension_uri = "https://purl.org/zarr/spec/storage_transformers/dummy/1.0"
valid_types = ["dummy_type"]

def __init__(self, _type, test_value) -> None:
super().__init__(_type)
assert test_value == self.TEST_CONSTANT
self.test_value = test_value


def test_ensure_store_v3():
class InvalidStore:
pass
Expand Down
6 changes: 3 additions & 3 deletions zarr/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from zarr.sync import ProcessSynchronizer, ThreadSynchronizer

# zarr_version fixture must be imported although not used directly here
from zarr.tests.test_attrs import TestAttributes, zarr_version # noqa
from zarr.tests.test_core import TestArray
from zarr.tests.test_hierarchy import TestGroup
from .test_attrs import TestAttributes, zarr_version # noqa
from .test_core import TestArray
from .test_hierarchy import TestGroup


class TestAttributesWithThreadSynchronizer(TestAttributes):
Expand Down
Loading