Skip to content

Commit 38ff517

Browse files
committed
continue renaming / test refactoring
1 parent a213058 commit 38ff517

File tree

5 files changed

+61
-80
lines changed

5 files changed

+61
-80
lines changed

src/zarr/abc/store.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def get_bytes(
248248
--------
249249
>>> store = await MemoryStore.open()
250250
>>> await store.set("data", Buffer.from_bytes(b"hello world"))
251-
>>> data = await store.get_bytes_async("data", prototype=default_buffer_prototype())
251+
>>> data = await store.get_bytes("data", prototype=default_buffer_prototype())
252252
>>> print(data)
253253
b'hello world'
254254
"""
@@ -263,8 +263,8 @@ def get_bytes_sync(
263263
"""
264264
Retrieve raw bytes from the store synchronously.
265265
266-
This is a synchronous wrapper around ``get_bytes_async()``. It should only
267-
be called from non-async code. For async contexts, use ``get_bytes_async()``
266+
This is a synchronous wrapper around ``get_bytes()``. It should only
267+
be called from non-async code. For async contexts, use ``get_bytes()``
268268
instead.
269269
270270
Parameters
@@ -294,8 +294,8 @@ def get_bytes_sync(
294294
295295
See Also
296296
--------
297-
get_bytes_async : Asynchronous version of this method.
298-
get_json : Synchronous method for retrieving and parsing JSON data.
297+
get_bytes : Asynchronous version of this method.
298+
get_json_sync : Synchronous method for retrieving and parsing JSON data.
299299
300300
Examples
301301
--------

src/zarr/storage/_local.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ async def get_bytes(
317317
Retrieve raw bytes from the local store asynchronously.
318318
319319
This is a convenience override that makes the ``prototype`` parameter optional
320-
by defaulting to the standard buffer prototype. See the base ``Store.get_bytes_async``
320+
by defaulting to the standard buffer prototype. See the base ``Store.get_bytes``
321321
for full documentation.
322322
323323
Parameters
@@ -342,15 +342,15 @@ async def get_bytes(
342342
343343
See Also
344344
--------
345-
Store.get_bytes_async : Base implementation with full documentation.
346-
get_bytes : Synchronous version of this method.
345+
Store.get_bytes : Base implementation with full documentation.
346+
get_bytes_sync : Synchronous version of this method.
347347
348348
Examples
349349
--------
350350
>>> store = await LocalStore.open("data")
351351
>>> await store.set("data", Buffer.from_bytes(b"hello"))
352352
>>> # No need to specify prototype for LocalStore
353-
>>> data = await store.get_bytes_async("data")
353+
>>> data = await store.get_bytes("data")
354354
>>> print(data)
355355
b'hello'
356356
"""
@@ -394,12 +394,12 @@ def get_bytes_sync(
394394
395395
Warnings
396396
--------
397-
Do not call this method from async functions. Use ``get_bytes_async()`` instead.
397+
Do not call this method from async functions. Use ``get_bytes()`` instead.
398398
399399
See Also
400400
--------
401-
Store.get_bytes : Base implementation with full documentation.
402-
get_bytes_async : Asynchronous version of this method.
401+
Store.get_bytes_sync : Base implementation with full documentation.
402+
get_bytes : Asynchronous version of this method.
403403
404404
Examples
405405
--------
@@ -455,8 +455,8 @@ async def get_json(
455455
See Also
456456
--------
457457
Store.get_json : Base implementation with full documentation.
458-
get_json : Synchronous version of this method.
459-
get_bytes_async : Method for retrieving raw bytes without parsing.
458+
get_json_sync : Synchronous version of this method.
459+
get_bytes : Method for retrieving raw bytes without parsing.
460460
461461
Examples
462462
--------
@@ -517,9 +517,9 @@ def get_json_sync(
517517
518518
See Also
519519
--------
520-
Store.get_json : Base implementation with full documentation.
520+
Store.get_json_sync : Base implementation with full documentation.
521521
get_json : Asynchronous version of this method.
522-
get_bytes : Method for retrieving raw bytes without parsing.
522+
get_bytes_sync : Method for retrieving raw bytes without parsing.
523523
524524
Examples
525525
--------

src/zarr/storage/_memory.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def get_bytes(
186186
Retrieve raw bytes from the memory store asynchronously.
187187
188188
This is a convenience override that makes the ``prototype`` parameter optional
189-
by defaulting to the standard buffer prototype. See the base ``Store.get_bytes_async``
189+
by defaulting to the standard buffer prototype. See the base ``Store.get_bytes``
190190
for full documentation.
191191
192192
Parameters
@@ -211,15 +211,15 @@ async def get_bytes(
211211
212212
See Also
213213
--------
214-
Store.get_bytes_async : Base implementation with full documentation.
215-
get_bytes : Synchronous version of this method.
214+
Store.get_bytes : Base implementation with full documentation.
215+
get_bytes_sync : Synchronous version of this method.
216216
217217
Examples
218218
--------
219219
>>> store = await MemoryStore.open()
220220
>>> await store.set("data", Buffer.from_bytes(b"hello"))
221221
>>> # No need to specify prototype for MemoryStore
222-
>>> data = await store.get_bytes_async("data")
222+
>>> data = await store.get_bytes("data")
223223
>>> print(data)
224224
b'hello'
225225
"""
@@ -263,12 +263,12 @@ def get_bytes_sync(
263263
264264
Warnings
265265
--------
266-
Do not call this method from async functions. Use ``get_bytes_async()`` instead.
266+
Do not call this method from async functions. Use ``get_bytes()`` instead.
267267
268268
See Also
269269
--------
270-
Store.get_bytes : Base implementation with full documentation.
271-
get_bytes_async : Asynchronous version of this method.
270+
Store.get_bytes_sync : Base implementation with full documentation.
271+
get_bytes : Asynchronous version of this method.
272272
273273
Examples
274274
--------
@@ -324,8 +324,8 @@ async def get_json(
324324
See Also
325325
--------
326326
Store.get_json : Base implementation with full documentation.
327-
get_json : Synchronous version of this method.
328-
get_bytes_async : Method for retrieving raw bytes without parsing.
327+
get_json_sync : Synchronous version of this method.
328+
get_bytes : Method for retrieving raw bytes without parsing.
329329
330330
Examples
331331
--------
@@ -386,9 +386,9 @@ def get_json_sync(
386386
387387
See Also
388388
--------
389-
Store.get_json : Base implementation with full documentation.
389+
Store.get_json_sync : Base implementation with full documentation.
390390
get_json : Asynchronous version of this method.
391-
get_bytes : Method for retrieving raw bytes without parsing.
391+
get_bytes_sync : Method for retrieving raw bytes without parsing.
392392
393393
Examples
394394
--------

src/zarr/testing/store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ async def test_set_if_not_exists(self, store: S) -> None:
527527
result = await store.get("k2", default_buffer_prototype())
528528
assert result == new
529529

530-
async def test_get_bytes_async(self, store: S) -> None:
530+
async def test_get_bytes(self, store: S) -> None:
531531
"""
532-
Test that the get_bytes_async method reads bytes.
532+
Test that the get_bytes method reads bytes.
533533
"""
534534
data = b"hello world"
535535
key = "zarr.json"
@@ -540,7 +540,7 @@ async def test_get_bytes_async(self, store: S) -> None:
540540

541541
def test_get_bytes_sync(self, store: S) -> None:
542542
"""
543-
Test that the get_bytes method reads bytes.
543+
Test that the get_bytes_sync method reads bytes.
544544
"""
545545
data = b"hello world"
546546
key = "zarr.json"
@@ -549,7 +549,7 @@ def test_get_bytes_sync(self, store: S) -> None:
549549

550550
async def test_get_json(self, store: S) -> None:
551551
"""
552-
Test that the get_bytes_async method reads json.
552+
Test that the get_json method reads json.
553553
"""
554554
data = {"foo": "bar"}
555555
data_bytes = json.dumps(data).encode("utf-8")

tests/test_store/test_memory.py

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import re
45
from typing import TYPE_CHECKING, Any
56

@@ -9,12 +10,14 @@
910

1011
import zarr
1112
from zarr.core.buffer import Buffer, cpu, gpu
13+
from zarr.core.sync import sync
1214
from zarr.errors import ZarrUserWarning
1315
from zarr.storage import GpuMemoryStore, MemoryStore
1416
from zarr.testing.store import StoreTests
1517
from zarr.testing.utils import gpu_test
1618

1719
if TYPE_CHECKING:
20+
from zarr.core.buffer import BufferPrototype
1821
from zarr.core.common import ZarrFormat
1922

2023

@@ -76,75 +79,53 @@ async def test_deterministic_size(
7679
np.testing.assert_array_equal(a[:3], 1)
7780
np.testing.assert_array_equal(a[3:], 0)
7881

79-
async def test_get_bytes_with_prototype_none(self, store: MemoryStore) -> None:
80-
"""Test that get_bytes_async works with prototype=None."""
81-
from zarr.core.buffer.core import default_buffer_prototype
82-
82+
@pytest.mark.parametrize("buffer_cls", [None, cpu.buffer_prototype])
83+
async def test_get_bytes_with_prototype_none(
84+
self, store: MemoryStore, buffer_cls: None | BufferPrototype
85+
) -> None:
86+
"""Test that get_bytes works with prototype=None."""
8387
data = b"hello world"
8488
key = "test_key"
8589
await self.set(store, key, self.buffer_cls.from_bytes(data))
8690

87-
# Test with None (default)
88-
result_none = await store.get_bytes(key)
89-
assert result_none == data
90-
91-
# Test with explicit prototype
92-
result_proto = await store.get_bytes(key, prototype=default_buffer_prototype())
93-
assert result_proto == data
94-
95-
def test_get_bytes_sync_with_prototype_none(self, store: MemoryStore) -> None:
96-
"""Test that get_bytes works with prototype=None."""
97-
from zarr.core.buffer.core import default_buffer_prototype
98-
from zarr.core.sync import sync
91+
result = await store.get_bytes(key, prototype=buffer_cls)
92+
assert result == data
9993

94+
@pytest.mark.parametrize("buffer_cls", [None, cpu.buffer_prototype])
95+
def test_get_bytes_sync_with_prototype_none(
96+
self, store: MemoryStore, buffer_cls: None | BufferPrototype
97+
) -> None:
98+
"""Test that get_bytes_sync works with prototype=None."""
10099
data = b"hello world"
101100
key = "test_key"
102101
sync(self.set(store, key, self.buffer_cls.from_bytes(data)))
103102

104-
# Test with None (default)
105-
result_none = store.get_bytes_sync(key)
106-
assert result_none == data
103+
result = store.get_bytes_sync(key, prototype=buffer_cls)
104+
assert result == data
107105

108-
# Test with explicit prototype
109-
result_proto = store.get_bytes_sync(key, prototype=default_buffer_prototype())
110-
assert result_proto == data
111-
112-
async def test_get_json_with_prototype_none(self, store: MemoryStore) -> None:
106+
@pytest.mark.parametrize("buffer_cls", [None, cpu.buffer_prototype])
107+
async def test_get_json_with_prototype_none(
108+
self, store: MemoryStore, buffer_cls: None | BufferPrototype
109+
) -> None:
113110
"""Test that get_json works with prototype=None."""
114-
import json
115-
116-
from zarr.core.buffer.core import default_buffer_prototype
117-
118111
data = {"foo": "bar", "number": 42}
119112
key = "test.json"
120113
await self.set(store, key, self.buffer_cls.from_bytes(json.dumps(data).encode()))
121114

122-
# Test with None (default)
123-
result_none = await store.get_json(key)
124-
assert result_none == data
125-
126-
# Test with explicit prototype
127-
result_proto = await store.get_json(key, prototype=default_buffer_prototype())
128-
assert result_proto == data
129-
130-
def test_get_json_sync_with_prototype_none(self, store: MemoryStore) -> None:
131-
"""Test that get_json works with prototype=None."""
132-
import json
133-
134-
from zarr.core.buffer.core import default_buffer_prototype
135-
from zarr.core.sync import sync
115+
result = await store.get_json(key, prototype=buffer_cls)
116+
assert result == data
136117

118+
@pytest.mark.parametrize("buffer_cls", [None, cpu.buffer_prototype])
119+
def test_get_json_sync_with_prototype_none(
120+
self, store: MemoryStore, buffer_cls: None | BufferPrototype
121+
) -> None:
122+
"""Test that get_json_sync works with prototype=None."""
137123
data = {"foo": "bar", "number": 42}
138124
key = "test.json"
139125
sync(self.set(store, key, self.buffer_cls.from_bytes(json.dumps(data).encode())))
140126

141-
# Test with None (default)
142-
result_none = store.get_json_sync(key)
143-
assert result_none == data
144-
145-
# Test with explicit prototype
146-
result_proto = store.get_json_sync(key, prototype=default_buffer_prototype())
147-
assert result_proto == data
127+
result = store.get_json_sync(key, prototype=buffer_cls)
128+
assert result == data
148129

149130

150131
# TODO: fix this warning

0 commit comments

Comments
 (0)