From 9f825e1d5df4bfb9c322fe172cb24408b83f383f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 26 Sep 2024 00:23:45 +0200 Subject: [PATCH] Enforce ruff/flake8-pytest-style rules (PT) (#2236) * Apply ruff/flake8-pytest-style rule PT018 PT018 Assertion should be broken down into multiple parts * Apply ruff/flake8-pytest-style rule PT007 PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` * Apply ruff/flake8-pytest-style rule PT006 PT006 Wrong type passed to first argument of `@pytest.mark.parametrize`; expected `tuple` * Apply ruff/flake8-pytest-style rule PT003 PT003 `scope='function'` is implied in `@pytest.fixture()` * Apply ruff/flake8-pytest-style rule PT001 PT001 Use `@pytest.fixture` over `@pytest.fixture()` * Enforce ruff/flake8-pytest-style rules (PT) --- pyproject.toml | 4 ++++ src/zarr/testing/store.py | 10 +++++----- tests/v3/conftest.py | 12 ++++++------ tests/v3/test_array.py | 22 +++++++++++----------- tests/v3/test_chunk_grids.py | 4 ++-- tests/v3/test_codec_entrypoints.py | 2 +- tests/v3/test_codecs/test_blosc.py | 2 +- tests/v3/test_codecs/test_codecs.py | 16 ++++++++-------- tests/v3/test_codecs/test_endian.py | 4 ++-- tests/v3/test_codecs/test_gzip.py | 2 +- tests/v3/test_codecs/test_sharding.py | 19 ++++++++++--------- tests/v3/test_codecs/test_transpose.py | 6 +++--- tests/v3/test_codecs/test_zstd.py | 2 +- tests/v3/test_config.py | 8 ++++---- tests/v3/test_group.py | 16 ++++++++-------- tests/v3/test_indexing.py | 14 +++++++------- tests/v3/test_metadata/test_v3.py | 4 ++-- tests/v3/test_store/test_memory.py | 8 ++++---- tests/v3/test_store/test_remote.py | 6 +++--- tests/v3/test_store/test_zip.py | 2 +- 20 files changed, 84 insertions(+), 79 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8b50870eb..a10c22d08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -212,6 +212,7 @@ extend-select = [ "I", # isort "ISC", # flake8-implicit-str-concat "PGH", # pygrep-hooks + "PT", # flake8-pytest-style "PYI", # flake8-pyi "RSE", # flake8-raise "RET", # flake8-return @@ -221,6 +222,9 @@ extend-select = [ "UP", # pyupgrade ] ignore = [ + "PT004", # deprecated + "PT011", # TODO: apply this rule + "PT012", # TODO: apply this rule "PYI013", "RET505", "RET506", diff --git a/src/zarr/testing/store.py b/src/zarr/testing/store.py index ebd4b85c9..70d2e16ef 100644 --- a/src/zarr/testing/store.py +++ b/src/zarr/testing/store.py @@ -37,11 +37,11 @@ def get(self, store: S, key: str) -> Buffer: raise NotImplementedError - @pytest.fixture(scope="function") + @pytest.fixture def store_kwargs(self) -> dict[str, Any]: return {"mode": "r+"} - @pytest.fixture(scope="function") + @pytest.fixture async def store(self, store_kwargs: dict[str, Any]) -> Store: return await self.store_cls.open(**store_kwargs) @@ -97,7 +97,7 @@ def test_store_supports_listing(self, store: S) -> None: @pytest.mark.parametrize("key", ["c/0", "foo/c/0.0", "foo/0/0"]) @pytest.mark.parametrize("data", [b"\x01\x02\x03\x04", b""]) - @pytest.mark.parametrize("byte_range", (None, (0, None), (1, None), (1, 2), (None, 1))) + @pytest.mark.parametrize("byte_range", [None, (0, None), (1, None), (1, 2), (None, 1)]) async def test_get( self, store: S, key: str, data: bytes, byte_range: None | tuple[int | None, int | None] ) -> None: @@ -137,12 +137,12 @@ async def test_set_many(self, store: S) -> None: @pytest.mark.parametrize( "key_ranges", - ( + [ [], [("zarr.json", (0, 1))], [("c/0", (0, 1)), ("zarr.json", (0, None))], [("c/0/0", (0, 1)), ("c/0/1", (None, 2)), ("c/0/2", (0, 3))], - ), + ], ) async def test_get_partial_values( self, store: S, key_ranges: list[tuple[str, tuple[int | None, int | None]]] diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index 4a2ef2643..fc1f950ad 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -49,27 +49,27 @@ async def store_path(tmpdir: LEGACY_PATH) -> StorePath: return StorePath(store) -@pytest.fixture(scope="function") +@pytest.fixture async def local_store(tmpdir: LEGACY_PATH) -> LocalStore: return await LocalStore.open(str(tmpdir), mode="w") -@pytest.fixture(scope="function") +@pytest.fixture async def remote_store(url: str) -> RemoteStore: return await RemoteStore.open(url, mode="w") -@pytest.fixture(scope="function") +@pytest.fixture async def memory_store() -> MemoryStore: return await MemoryStore.open(mode="w") -@pytest.fixture(scope="function") +@pytest.fixture async def zip_store(tmpdir: LEGACY_PATH) -> ZipStore: return await ZipStore.open(str(tmpdir / "zarr.zip"), mode="w") -@pytest.fixture(scope="function") +@pytest.fixture async def store(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> Store: param = request.param return await parse_store(param, str(tmpdir)) @@ -82,7 +82,7 @@ class AsyncGroupRequest: attributes: dict[str, Any] = field(default_factory=dict) -@pytest.fixture(scope="function") +@pytest.fixture async def async_group(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> AsyncGroup: param: AsyncGroupRequest = request.param diff --git a/tests/v3/test_array.py b/tests/v3/test_array.py index 06fd791e6..02358cb39 100644 --- a/tests/v3/test_array.py +++ b/tests/v3/test_array.py @@ -12,8 +12,8 @@ from zarr.store.common import StorePath -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) @pytest.mark.parametrize("exists_ok", [True, False]) @pytest.mark.parametrize("extant_node", ["array", "group"]) def test_array_creation_existing_node( @@ -61,8 +61,8 @@ def test_array_creation_existing_node( ) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) def test_array_name_properties_no_group( store: LocalStore | MemoryStore, zarr_format: ZarrFormat ) -> None: @@ -72,8 +72,8 @@ def test_array_name_properties_no_group( assert arr.basename is None -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) def test_array_name_properties_with_group( store: LocalStore | MemoryStore, zarr_format: ZarrFormat ) -> None: @@ -123,7 +123,7 @@ def test_array_v3_fill_value_default( @pytest.mark.parametrize("store", ["memory"], indirect=True) @pytest.mark.parametrize( - "dtype_str,fill_value", + ("dtype_str", "fill_value"), [("bool", True), ("uint8", 99), ("float32", -99.9), ("complex64", 3 + 4j)], ) def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str) -> None: @@ -201,8 +201,8 @@ async def test_array_v3_nan_fill_value(store: MemoryStore) -> None: assert len([a async for a in store.list_prefix("/")]) == 0 -@pytest.mark.parametrize("store", ("local",), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) async def test_serializable_async_array( store: LocalStore | MemoryStore, zarr_format: ZarrFormat ) -> None: @@ -219,8 +219,8 @@ async def test_serializable_async_array( # TODO: uncomment the parts of this test that will be impacted by the config/prototype changes in flight -@pytest.mark.parametrize("store", ("local",), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) def test_serializable_sync_array(store: LocalStore, zarr_format: ZarrFormat) -> None: expected = Array.create( store=store, shape=(100,), chunks=(10,), zarr_format=zarr_format, dtype="i4" diff --git a/tests/v3/test_chunk_grids.py b/tests/v3/test_chunk_grids.py index e1b4df10a..12166bd21 100644 --- a/tests/v3/test_chunk_grids.py +++ b/tests/v3/test_chunk_grids.py @@ -5,9 +5,9 @@ @pytest.mark.parametrize( - "shape", ((0,), (0,) * 2, (1, 2, 0, 4, 5), (10, 0), (10,), (100,) * 3, (1000000,), (10000,) * 2) + "shape", [(0,), (0,) * 2, (1, 2, 0, 4, 5), (10, 0), (10,), (100,) * 3, (1000000,), (10000,) * 2] ) -@pytest.mark.parametrize("itemsize", (1, 2, 4)) +@pytest.mark.parametrize("itemsize", [1, 2, 4]) def test_guess_chunks(shape: tuple[int, ...], itemsize: int) -> None: chunks = _guess_chunks(shape, itemsize) chunk_size = np.prod(chunks) * itemsize diff --git a/tests/v3/test_codec_entrypoints.py b/tests/v3/test_codec_entrypoints.py index 95dae6876..e1ef027dd 100644 --- a/tests/v3/test_codec_entrypoints.py +++ b/tests/v3/test_codec_entrypoints.py @@ -10,7 +10,7 @@ here = os.path.abspath(os.path.dirname(__file__)) -@pytest.fixture() +@pytest.fixture def set_path() -> Generator[None, None, None]: sys.path.append(here) zarr.registry._collect_entrypoints() diff --git a/tests/v3/test_codecs/test_blosc.py b/tests/v3/test_codecs/test_blosc.py index 4c569055b..982b0213b 100644 --- a/tests/v3/test_codecs/test_blosc.py +++ b/tests/v3/test_codecs/test_blosc.py @@ -10,7 +10,7 @@ from zarr.store.common import StorePath -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("dtype", ["uint8", "uint16"]) async def test_blosc_evolve(store: Store, dtype: str) -> None: typesize = np.dtype(dtype).itemsize diff --git a/tests/v3/test_codecs/test_codecs.py b/tests/v3/test_codecs/test_codecs.py index 8e98cf20f..75b1d15d0 100644 --- a/tests/v3/test_codecs/test_codecs.py +++ b/tests/v3/test_codecs/test_codecs.py @@ -59,7 +59,7 @@ def test_sharding_pickle() -> None: pass -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("input_order", ["F", "C"]) @pytest.mark.parametrize("store_order", ["F", "C"]) @pytest.mark.parametrize("runtime_write_order", ["F", "C"]) @@ -117,7 +117,7 @@ async def test_order( assert read_data.flags["C_CONTIGUOUS"] -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("input_order", ["F", "C"]) @pytest.mark.parametrize("runtime_write_order", ["F", "C"]) @pytest.mark.parametrize("runtime_read_order", ["F", "C"]) @@ -159,7 +159,7 @@ def test_order_implicit( assert read_data.flags["C_CONTIGUOUS"] -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_open(store: Store) -> None: spath = StorePath(store) a = Array.create( @@ -205,7 +205,7 @@ def test_morton() -> None: ] -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_write_partial_chunks(store: Store) -> None: data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) spath = StorePath(store) @@ -220,7 +220,7 @@ def test_write_partial_chunks(store: Store) -> None: assert np.array_equal(a[0:16, 0:16], data) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) async def test_delete_empty_chunks(store: Store) -> None: data = np.ones((16, 16)) path = "delete_empty_chunks" @@ -238,7 +238,7 @@ async def test_delete_empty_chunks(store: Store) -> None: assert await store.get(f"{path}/c0/0", prototype=default_buffer_prototype()) is None -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) async def test_dimension_names(store: Store) -> None: data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) path = "dimension_names" @@ -272,7 +272,7 @@ async def test_dimension_names(store: Store) -> None: assert "dimension_names" not in json.loads(zarr_json_buffer.to_bytes()) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_invalid_metadata(store: Store) -> None: spath = StorePath(store, "invalid_metadata") with pytest.raises(ValueError): @@ -360,7 +360,7 @@ def test_invalid_metadata(store: Store) -> None: ) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) async def test_resize(store: Store) -> None: data = np.zeros((16, 18), dtype="uint16") path = "resize" diff --git a/tests/v3/test_codecs/test_endian.py b/tests/v3/test_codecs/test_endian.py index 5b5b2eb89..81b24e734 100644 --- a/tests/v3/test_codecs/test_endian.py +++ b/tests/v3/test_codecs/test_endian.py @@ -11,7 +11,7 @@ from .test_codecs import _AsyncArrayProxy -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("endian", ["big", "little"]) async def test_endian(store: Store, endian: Literal["big", "little"]) -> None: data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) @@ -32,7 +32,7 @@ async def test_endian(store: Store, endian: Literal["big", "little"]) -> None: assert np.array_equal(data, readback_data) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("dtype_input_endian", [">u2", " None: data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) diff --git a/tests/v3/test_codecs/test_sharding.py b/tests/v3/test_codecs/test_sharding.py index bd8aab5e0..ecf2ea7bd 100644 --- a/tests/v3/test_codecs/test_sharding.py +++ b/tests/v3/test_codecs/test_sharding.py @@ -21,7 +21,7 @@ from .test_codecs import _AsyncArrayProxy, order_from_dim -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) @pytest.mark.parametrize("index_location", ["start", "end"]) @pytest.mark.parametrize( "array_fixture", @@ -76,7 +76,7 @@ def test_sharding( @pytest.mark.parametrize("index_location", ["start", "end"]) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) @pytest.mark.parametrize( "array_fixture", [ @@ -126,7 +126,7 @@ def test_sharding_partial( indirect=["array_fixture"], ) @pytest.mark.parametrize("index_location", ["start", "end"]) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) def test_sharding_partial_read( store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation ) -> None: @@ -163,7 +163,7 @@ def test_sharding_partial_read( indirect=["array_fixture"], ) @pytest.mark.parametrize("index_location", ["start", "end"]) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) def test_sharding_partial_overwrite( store: Store, array_fixture: npt.NDArray[Any], index_location: ShardingCodecIndexLocation ) -> None: @@ -214,7 +214,7 @@ def test_sharding_partial_overwrite( "inner_index_location", ["start", "end"], ) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) def test_nested_sharding( store: Store, array_fixture: npt.NDArray[Any], @@ -247,7 +247,7 @@ def test_nested_sharding( assert np.array_equal(data, read_data) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) def test_open_sharding(store: Store) -> None: path = "open_sharding" spath = StorePath(store, path) @@ -272,7 +272,7 @@ def test_open_sharding(store: Store) -> None: assert a.metadata == b.metadata -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) def test_write_partial_sharded_chunks(store: Store) -> None: data = np.arange(0, 16 * 16, dtype="uint16").reshape((16, 16)) spath = StorePath(store) @@ -296,7 +296,7 @@ def test_write_partial_sharded_chunks(store: Store) -> None: assert np.array_equal(a[0:16, 0:16], data) -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) async def test_delete_empty_shards(store: Store) -> None: if not store.supports_deletes: pytest.skip("store does not support deletes") @@ -323,7 +323,8 @@ async def test_delete_empty_shards(store: Store) -> None: assert np.array_equal(data, await _AsyncArrayProxy(a)[:, :].get()) assert await store.get(f"{path}/c/1/0", prototype=default_buffer_prototype()) is None chunk_bytes = await store.get(f"{path}/c/0/0", prototype=default_buffer_prototype()) - assert chunk_bytes is not None and len(chunk_bytes) == 16 * 2 + 8 * 8 * 2 + 4 + assert chunk_bytes is not None + assert len(chunk_bytes) == 16 * 2 + 8 * 8 * 2 + 4 def test_pickle() -> None: diff --git a/tests/v3/test_codecs/test_transpose.py b/tests/v3/test_codecs/test_transpose.py index 4eff57bab..a14ace720 100644 --- a/tests/v3/test_codecs/test_transpose.py +++ b/tests/v3/test_codecs/test_transpose.py @@ -19,7 +19,7 @@ @pytest.mark.parametrize("runtime_write_order", ["F", "C"]) @pytest.mark.parametrize("runtime_read_order", ["F", "C"]) @pytest.mark.parametrize("with_sharding", [True, False]) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) async def test_transpose( store: Store, input_order: MemoryOrder, @@ -69,7 +69,7 @@ async def test_transpose( assert read_data.flags["C_CONTIGUOUS"] -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("order", [[1, 2, 0], [1, 2, 3, 0], [3, 2, 4, 0, 1]]) def test_transpose_non_self_inverse(store: Store, order: list[int]) -> None: shape = [i + 3 for i in range(len(order))] @@ -88,7 +88,7 @@ def test_transpose_non_self_inverse(store: Store, order: list[int]) -> None: assert np.array_equal(data, read_data) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_transpose_invalid( store: Store, ) -> None: diff --git a/tests/v3/test_codecs/test_zstd.py b/tests/v3/test_codecs/test_zstd.py index 0726e5944..cf80a8053 100644 --- a/tests/v3/test_codecs/test_zstd.py +++ b/tests/v3/test_codecs/test_zstd.py @@ -7,7 +7,7 @@ from zarr.store.common import StorePath -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) @pytest.mark.parametrize("checksum", [True, False]) def test_zstd(store: Store, checksum: bool) -> None: data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) diff --git a/tests/v3/test_config.py b/tests/v3/test_config.py index 115487ba8..79b28055d 100644 --- a/tests/v3/test_config.py +++ b/tests/v3/test_config.py @@ -69,7 +69,7 @@ def test_config_defaults_set() -> None: @pytest.mark.parametrize( - "key, old_val, new_val", + ("key", "old_val", "new_val"), [("array.order", "C", "F"), ("async.concurrency", None, 10), ("json_indent", 2, 0)], ) def test_config_defaults_can_be_overridden(key: str, old_val: Any, new_val: Any) -> None: @@ -88,7 +88,7 @@ class MockClass: ) -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_config_codec_pipeline_class(store: Store) -> None: # has default value assert get_pipeline_class().__name__ != "" @@ -139,7 +139,7 @@ class MockEnvCodecPipeline(CodecPipeline): assert get_pipeline_class(reload_config=True) == MockEnvCodecPipeline -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_config_codec_implementation(store: Store) -> None: # has default value assert fully_qualified_name(get_codec_class("blosc")) == config.defaults[0]["codecs"]["blosc"] @@ -172,7 +172,7 @@ async def _encode_single( assert get_codec_class("blosc", reload_config=True) == BloscCodec -@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) def test_config_ndbuffer_implementation(store: Store) -> None: # has default value assert fully_qualified_name(get_ndbuffer_class()) == config.defaults[0]["ndbuffer"] diff --git a/tests/v3/test_group.py b/tests/v3/test_group.py index 8beb344b4..22499dfb4 100644 --- a/tests/v3/test_group.py +++ b/tests/v3/test_group.py @@ -453,8 +453,8 @@ def test_group_array_creation( assert full_like_array.store_path.store == store -@pytest.mark.parametrize("store", ("local", "memory", "zip"), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) @pytest.mark.parametrize("exists_ok", [True, False]) @pytest.mark.parametrize("extant_node", ["array", "group"]) def test_group_creation_existing_node( @@ -601,10 +601,10 @@ async def test_asyncgroup_open_wrong_format( # should this be async? @pytest.mark.parametrize( "data", - ( + [ {"zarr_format": 3, "node_type": "group", "attributes": {"foo": 100}}, {"zarr_format": 2, "attributes": {"foo": 100}}, - ), + ], ) def test_asyncgroup_from_dict(store: Store, data: dict[str, Any]) -> None: """ @@ -744,8 +744,8 @@ async def test_asyncgroup_update_attributes(store: Store, zarr_format: ZarrForma assert agroup_new_attributes.attrs == attributes_new -@pytest.mark.parametrize("store", ("local",), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) async def test_serializable_async_group(store: LocalStore, zarr_format: ZarrFormat) -> None: expected = await AsyncGroup.from_store( store=store, attributes={"foo": 999}, zarr_format=zarr_format @@ -755,8 +755,8 @@ async def test_serializable_async_group(store: LocalStore, zarr_format: ZarrForm assert actual == expected -@pytest.mark.parametrize("store", ("local",), indirect=["store"]) -@pytest.mark.parametrize("zarr_format", (2, 3)) +@pytest.mark.parametrize("store", ["local"], indirect=["store"]) +@pytest.mark.parametrize("zarr_format", [2, 3]) def test_serializable_sync_group(store: LocalStore, zarr_format: ZarrFormat) -> None: expected = Group.from_store(store=store, attributes={"foo": 999}, zarr_format=zarr_format) p = pickle.dumps(expected) diff --git a/tests/v3/test_indexing.py b/tests/v3/test_indexing.py index d2cf455e0..890c487b0 100644 --- a/tests/v3/test_indexing.py +++ b/tests/v3/test_indexing.py @@ -130,7 +130,7 @@ def test_replace_ellipsis() -> None: @pytest.mark.parametrize( - "value, dtype", + ("value", "dtype"), [ (42, "uint8"), pytest.param( @@ -138,7 +138,7 @@ def test_replace_ellipsis() -> None: ), ], ) -@pytest.mark.parametrize("use_out", (True, False)) +@pytest.mark.parametrize("use_out", [True, False]) def test_get_basic_selection_0d(store: StorePath, use_out: bool, value: Any, dtype: Any) -> None: # setup arr_np = np.array(value, dtype=dtype) @@ -385,7 +385,7 @@ def test_fancy_indexing_fallback_on_get_setitem(store: StorePath) -> None: @pytest.mark.parametrize( - "index,expected_result", + ("index", "expected_result"), [ # Single iterable of integers ([0, 1], [[0, 1, 2], [3, 4, 5]]), @@ -426,7 +426,7 @@ def test_orthogonal_indexing_fallback_on_getitem_2d( @pytest.mark.parametrize( - "index,expected_result", + ("index", "expected_result"), [ # Single iterable of integers ([0, 1], [[[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[9, 10, 11], [12, 13, 14], [15, 16, 17]]]), @@ -466,7 +466,7 @@ def test_orthogonal_indexing_fallback_on_getitem_3d( @pytest.mark.parametrize( - "index,expected_result", + ("index", "expected_result"), [ # Single iterable of integers ([0, 1], [[1, 1, 1], [1, 1, 1], [0, 0, 0]]), @@ -509,7 +509,7 @@ def test_fancy_indexing_doesnt_mix_with_implicit_slicing(store: StorePath) -> No @pytest.mark.parametrize( - "value, dtype", + ("value", "dtype"), [ (42, "uint8"), pytest.param( @@ -1735,7 +1735,7 @@ def test_numpy_int_indexing(store: StorePath) -> None: @pytest.mark.parametrize( - "shape, chunks, ops", + ("shape", "chunks", "ops"), [ # 1D test cases ((1070,), (50,), [("__getitem__", (slice(200, 400),))]), diff --git a/tests/v3/test_metadata/test_v3.py b/tests/v3/test_metadata/test_v3.py index f8e2ebd7b..025d59422 100644 --- a/tests/v3/test_metadata/test_v3.py +++ b/tests/v3/test_metadata/test_v3.py @@ -82,7 +82,7 @@ def test_parse_auto_fill_value(dtype_str: str) -> None: @pytest.mark.parametrize( - "fill_value,dtype_str", + ("fill_value", "dtype_str"), [ (True, "bool"), (False, "bool"), @@ -301,7 +301,7 @@ def test_parse_invalid_dtype_raises(data): @pytest.mark.parametrize( - "data_type,fill_value", [("uint8", -1), ("int32", 22.5), ("float32", "foo")] + ("data_type", "fill_value"), [("uint8", -1), ("int32", 22.5), ("float32", "foo")] ) async def test_invalid_fill_value_raises(data_type: str, fill_value: float) -> None: metadata_dict = { diff --git a/tests/v3/test_store/test_memory.py b/tests/v3/test_store/test_memory.py index 2498cdc24..441304717 100644 --- a/tests/v3/test_store/test_memory.py +++ b/tests/v3/test_store/test_memory.py @@ -18,7 +18,7 @@ def set(self, store: MemoryStore, key: str, value: Buffer) -> None: def get(self, store: MemoryStore, key: str) -> Buffer: return store._store_dict[key] - @pytest.fixture(scope="function", params=[None, True]) + @pytest.fixture(params=[None, True]) def store_kwargs( self, request: pytest.FixtureRequest ) -> dict[str, str | None | dict[str, Buffer]]: @@ -27,7 +27,7 @@ def store_kwargs( kwargs["store_dict"] = {} return kwargs - @pytest.fixture(scope="function") + @pytest.fixture def store(self, store_kwargs: str | None | dict[str, Buffer]) -> MemoryStore: return self.store_cls(**store_kwargs) @@ -58,11 +58,11 @@ def set(self, store: GpuMemoryStore, key: str, value: Buffer) -> None: def get(self, store: MemoryStore, key: str) -> Buffer: return store._store_dict[key] - @pytest.fixture(scope="function", params=[None, {}]) + @pytest.fixture(params=[None, {}]) def store_kwargs(self, request) -> dict[str, str | None | dict[str, Buffer]]: return {"store_dict": request.param, "mode": "r+"} - @pytest.fixture(scope="function") + @pytest.fixture def store(self, store_kwargs: str | None | dict[str, gpu.Buffer]) -> GpuMemoryStore: return self.store_cls(**store_kwargs) diff --git a/tests/v3/test_store/test_remote.py b/tests/v3/test_store/test_remote.py index ac77a50f8..6010f7eca 100644 --- a/tests/v3/test_store/test_remote.py +++ b/tests/v3/test_store/test_remote.py @@ -55,7 +55,7 @@ def get_boto3_client() -> botocore.client.BaseClient: return session.create_client("s3", endpoint_url=endpoint_url) -@pytest.fixture(autouse=True, scope="function") +@pytest.fixture(autouse=True) def s3(s3_base: None) -> Generator[s3fs.S3FileSystem, None, None]: """ Quoting Martin Durant: @@ -110,14 +110,14 @@ class TestRemoteStoreS3(StoreTests[RemoteStore, cpu.Buffer]): store_cls = RemoteStore buffer_cls = cpu.Buffer - @pytest.fixture(scope="function") + @pytest.fixture def store_kwargs(self, request) -> dict[str, str | bool]: fs, path = fsspec.url_to_fs( f"s3://{test_bucket_name}", endpoint_url=endpoint_url, anon=False ) return {"fs": fs, "path": path, "mode": "r+"} - @pytest.fixture(scope="function") + @pytest.fixture def store(self, store_kwargs: dict[str, str | bool]) -> RemoteStore: return self.store_cls(**store_kwargs) diff --git a/tests/v3/test_store/test_zip.py b/tests/v3/test_store/test_zip.py index 7c332e9a2..595d1a3e5 100644 --- a/tests/v3/test_store/test_zip.py +++ b/tests/v3/test_store/test_zip.py @@ -22,7 +22,7 @@ class TestZipStore(StoreTests[ZipStore, cpu.Buffer]): store_cls = ZipStore buffer_cls = cpu.Buffer - @pytest.fixture(scope="function") + @pytest.fixture def store_kwargs(self, request) -> dict[str, str | bool]: fd, temp_path = tempfile.mkstemp() os.close(fd)