|
1 | 1 | import asyncio |
2 | | -import time |
3 | | -from collections.abc import Iterable |
4 | | -from contextlib import asynccontextmanager |
5 | 2 | from typing import Literal, TypeVar |
6 | 3 | from unittest.mock import patch |
7 | 4 |
|
|
21 | 18 |
|
22 | 19 | T_Store = TypeVar("T_Store", bound=Store) |
23 | 20 |
|
24 | | - class LatencyStore(WrapperStore[T_Store]): |
25 | | - """Works the same way as the zarr LoggingStore""" |
| 21 | + class ReadOnlyStore(WrapperStore[T_Store]): |
| 22 | + """ |
| 23 | + We shouldn't need this - but we currently do just as a way around https://github.com/zarr-developers/zarr-python/issues/3105#issuecomment-2990367167 |
26 | 24 |
|
27 | | - latency: float |
| 25 | + Works the same way as the zarr LoggingStore. |
| 26 | + """ |
28 | 27 |
|
29 | | - # TODO only have to add this because of dumb behaviour in zarr where it raises with "ValueError: Store is not read-only but mode is 'r'" |
30 | 28 | read_only = True |
31 | 29 |
|
32 | 30 | def __init__( |
33 | 31 | self, |
34 | 32 | store: T_Store, |
35 | | - latency: float = 0.0, |
36 | 33 | ) -> None: |
37 | | - """ |
38 | | - Store wrapper that adds artificial latency to each get call. |
39 | | -
|
40 | | - Parameters |
41 | | - ---------- |
42 | | - store : Store |
43 | | - Store to wrap |
44 | | - latency : float |
45 | | - Amount of artificial latency to add to each get call, in seconds. |
46 | | - """ |
47 | 34 | super().__init__(store) |
48 | | - self.latency = latency |
49 | | - |
50 | | - def __str__(self) -> str: |
51 | | - return f"latency-{self._store}" |
52 | | - |
53 | | - def __repr__(self) -> str: |
54 | | - return f"LatencyStore({self._store.__class__.__name__}, '{self._store}', latency={self.latency})" |
55 | 35 |
|
56 | 36 | async def get( |
57 | 37 | self, |
58 | 38 | key: str, |
59 | 39 | prototype: BufferPrototype, |
60 | 40 | byte_range: ByteRequest | None = None, |
61 | 41 | ) -> Buffer | None: |
62 | | - await asyncio.sleep(self.latency) |
63 | 42 | return await self._store.get( |
64 | 43 | key=key, prototype=prototype, byte_range=byte_range |
65 | 44 | ) |
66 | 45 |
|
67 | | - async def get_partial_values( |
68 | | - self, |
69 | | - prototype: BufferPrototype, |
70 | | - key_ranges: Iterable[tuple[str, ByteRequest | None]], |
71 | | - ) -> list[Buffer | None]: |
72 | | - await asyncio.sleep(self.latency) |
73 | | - return await self._store.get_partial_values( |
74 | | - prototype=prototype, key_ranges=key_ranges |
75 | | - ) |
76 | 46 | else: |
77 | | - LatencyStore = {} |
| 47 | + ReadOnlyStore = {} |
78 | 48 |
|
79 | 49 |
|
80 | 50 | @pytest.fixture |
@@ -106,8 +76,8 @@ def memorystore() -> "MemoryStore": |
106 | 76 |
|
107 | 77 | @pytest.fixture |
108 | 78 | def store(memorystore) -> "zarr.abc.store.Store": |
109 | | - # TODO we shouldn't need a LatencyStore at all for the patched tests, but we currently use it just as a way around https://github.com/zarr-developers/zarr-python/issues/3105#issuecomment-2990367167 |
110 | | - return LatencyStore(memorystore, latency=0.0) |
| 79 | + # TODO we shouldn't this Store at all for the patched tests, but we currently use it just as a way around https://github.com/zarr-developers/zarr-python/issues/3105#issuecomment-2990367167 |
| 80 | + return ReadOnlyStore(memorystore) |
111 | 81 |
|
112 | 82 |
|
113 | 83 | def get_xr_obj( |
|
0 commit comments