Skip to content

Commit 2824de6

Browse files
committed
fixup
1 parent d236e53 commit 2824de6

File tree

1 file changed

+0
-279
lines changed

1 file changed

+0
-279
lines changed

tests/v3/test_metadata/test_v3.py

Lines changed: 0 additions & 279 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,17 @@
77
import numpy as np
88
import pytest
99

10-
import zarr.api.synchronous
11-
from zarr.api.asynchronous import (
12-
AsyncGroup,
13-
consolidate_metadata,
14-
group,
15-
open,
16-
open_consolidated,
17-
)
1810
from zarr.codecs.bytes import BytesCodec
1911
from zarr.core.buffer import default_buffer_prototype
2012
from zarr.core.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding
21-
from zarr.core.group import ConsolidatedMetadata, GroupMetadata
2213
from zarr.core.metadata import ArrayV3Metadata
2314
from zarr.core.metadata.v3 import parse_dimension_names, parse_fill_value, parse_zarr_format
24-
from zarr.store.common import StorePath
2515

2616
if TYPE_CHECKING:
2717
from collections.abc import Sequence
2818
from typing import Any
2919

3020
from zarr.abc.codec import Codec
31-
from zarr.abc.store import Store
3221

3322
bool_dtypes = ("bool",)
3423

@@ -262,271 +251,3 @@ async def test_datetime_metadata(fill_value: int, precision: str) -> None:
262251

263252
result = json.loads(d["zarr.json"].to_bytes())
264253
assert result["fill_value"] == fill_value
265-
266-
267-
@pytest.fixture
268-
async def memory_store_with_hierarchy(memory_store: Store) -> None:
269-
g = await group(store=memory_store, attributes={"foo": "bar"})
270-
await g.create_array(name="air", shape=(1, 2, 3))
271-
await g.create_array(name="lat", shape=(1,))
272-
await g.create_array(name="lon", shape=(2,))
273-
await g.create_array(name="time", shape=(3,))
274-
275-
child = await g.create_group("child", attributes={"key": "child"})
276-
await child.create_array("array", shape=(4, 4), attributes={"key": "child"})
277-
278-
grandchild = await child.create_group("grandchild", attributes={"key": "grandchild"})
279-
await grandchild.create_array("array", shape=(4, 4), attributes={"key": "grandchild"})
280-
return memory_store
281-
282-
283-
class TestConsolidated:
284-
async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None:
285-
# TODO: Figure out desired keys in
286-
# TODO: variety in the hierarchies
287-
# More nesting
288-
# arrays under arrays
289-
# single array
290-
# etc.
291-
await consolidate_metadata(memory_store_with_hierarchy)
292-
group2 = await AsyncGroup.open(memory_store_with_hierarchy)
293-
294-
array_metadata = {
295-
"attributes": {},
296-
"chunk_key_encoding": {
297-
"configuration": {"separator": "/"},
298-
"name": "default",
299-
},
300-
"codecs": ({"configuration": {"endian": "little"}, "name": "bytes"},),
301-
"data_type": np.dtype("float64"),
302-
"fill_value": np.float64(0.0),
303-
"node_type": "array",
304-
# "shape": (1, 2, 3),
305-
"zarr_format": 3,
306-
}
307-
308-
expected = GroupMetadata(
309-
attributes={"foo": "bar"},
310-
consolidated_metadata=ConsolidatedMetadata(
311-
kind="inline",
312-
must_understand=False,
313-
metadata={
314-
"air": ArrayV3Metadata.from_dict(
315-
{
316-
**{
317-
"shape": (1, 2, 3),
318-
"chunk_grid": {
319-
"configuration": {"chunk_shape": (1, 2, 3)},
320-
"name": "regular",
321-
},
322-
},
323-
**array_metadata,
324-
}
325-
),
326-
"lat": ArrayV3Metadata.from_dict(
327-
{
328-
**{
329-
"shape": (1,),
330-
"chunk_grid": {
331-
"configuration": {"chunk_shape": (1,)},
332-
"name": "regular",
333-
},
334-
},
335-
**array_metadata,
336-
}
337-
),
338-
"lon": ArrayV3Metadata.from_dict(
339-
{
340-
**{"shape": (2,)},
341-
"chunk_grid": {
342-
"configuration": {"chunk_shape": (2,)},
343-
"name": "regular",
344-
},
345-
**array_metadata,
346-
}
347-
),
348-
"time": ArrayV3Metadata.from_dict(
349-
{
350-
**{
351-
"shape": (3,),
352-
"chunk_grid": {
353-
"configuration": {"chunk_shape": (3,)},
354-
"name": "regular",
355-
},
356-
},
357-
**array_metadata,
358-
}
359-
),
360-
"child": GroupMetadata(
361-
attributes={"key": "child"},
362-
consolidated_metadata=ConsolidatedMetadata(
363-
metadata={
364-
"array": ArrayV3Metadata.from_dict(
365-
{
366-
**array_metadata,
367-
**{
368-
"attributes": {"key": "child"},
369-
"shape": (4, 4),
370-
"chunk_grid": {
371-
"configuration": {"chunk_shape": (4, 4)},
372-
"name": "regular",
373-
},
374-
},
375-
}
376-
),
377-
"grandchild": GroupMetadata(
378-
attributes={"key": "grandchild"},
379-
consolidated_metadata=ConsolidatedMetadata(
380-
metadata={
381-
"array": ArrayV3Metadata.from_dict(
382-
{
383-
**array_metadata,
384-
**{
385-
"attributes": {"key": "grandchild"},
386-
"shape": (4, 4),
387-
"chunk_grid": {
388-
"configuration": {
389-
"chunk_shape": (4, 4)
390-
},
391-
"name": "regular",
392-
},
393-
},
394-
}
395-
)
396-
}
397-
),
398-
),
399-
},
400-
),
401-
),
402-
},
403-
),
404-
)
405-
406-
assert group2.metadata == expected
407-
group3 = await open(store=memory_store_with_hierarchy)
408-
assert group3.metadata == expected
409-
410-
group4 = await open_consolidated(store=memory_store_with_hierarchy)
411-
assert group4.metadata == expected
412-
413-
result_raw = json.loads(
414-
(
415-
await memory_store_with_hierarchy.get(
416-
"zarr.json", prototype=default_buffer_prototype()
417-
)
418-
).to_bytes()
419-
)["consolidated_metadata"]
420-
assert result_raw["kind"] == "inline"
421-
assert sorted(result_raw["metadata"]) == [
422-
"air",
423-
"child",
424-
"child/array",
425-
"child/grandchild",
426-
"child/grandchild/array",
427-
"lat",
428-
"lon",
429-
"time",
430-
]
431-
432-
def test_consolidated_sync(self, memory_store):
433-
g = zarr.api.synchronous.group(store=memory_store, attributes={"foo": "bar"})
434-
g.create_array(name="air", shape=(1, 2, 3))
435-
g.create_array(name="lat", shape=(1,))
436-
g.create_array(name="lon", shape=(2,))
437-
g.create_array(name="time", shape=(3,))
438-
439-
zarr.api.synchronous.consolidate_metadata(memory_store)
440-
group2 = zarr.api.synchronous.Group.open(memory_store)
441-
442-
array_metadata = {
443-
"attributes": {},
444-
"chunk_key_encoding": {
445-
"configuration": {"separator": "/"},
446-
"name": "default",
447-
},
448-
"codecs": ({"configuration": {"endian": "little"}, "name": "bytes"},),
449-
"data_type": np.dtype("float64"),
450-
"fill_value": np.float64(0.0),
451-
"node_type": "array",
452-
# "shape": (1, 2, 3),
453-
"zarr_format": 3,
454-
}
455-
456-
expected = GroupMetadata(
457-
attributes={"foo": "bar"},
458-
consolidated_metadata=ConsolidatedMetadata(
459-
kind="inline",
460-
must_understand=False,
461-
metadata={
462-
"air": ArrayV3Metadata.from_dict(
463-
{
464-
**{
465-
"shape": (1, 2, 3),
466-
"chunk_grid": {
467-
"configuration": {"chunk_shape": (1, 2, 3)},
468-
"name": "regular",
469-
},
470-
},
471-
**array_metadata,
472-
}
473-
),
474-
"lat": ArrayV3Metadata.from_dict(
475-
{
476-
**{
477-
"shape": (1,),
478-
"chunk_grid": {
479-
"configuration": {"chunk_shape": (1,)},
480-
"name": "regular",
481-
},
482-
},
483-
**array_metadata,
484-
}
485-
),
486-
"lon": ArrayV3Metadata.from_dict(
487-
{
488-
**{"shape": (2,)},
489-
"chunk_grid": {
490-
"configuration": {"chunk_shape": (2,)},
491-
"name": "regular",
492-
},
493-
**array_metadata,
494-
}
495-
),
496-
"time": ArrayV3Metadata.from_dict(
497-
{
498-
**{
499-
"shape": (3,),
500-
"chunk_grid": {
501-
"configuration": {"chunk_shape": (3,)},
502-
"name": "regular",
503-
},
504-
},
505-
**array_metadata,
506-
}
507-
),
508-
},
509-
),
510-
)
511-
assert group2.metadata == expected
512-
group3 = zarr.api.synchronous.open(store=memory_store)
513-
assert group3.metadata == expected
514-
515-
group4 = zarr.api.synchronous.open_consolidated(store=memory_store)
516-
assert group4.metadata == expected
517-
518-
async def test_not_writable_raises(self, memory_store: zarr.store.MemoryStore) -> None:
519-
await group(store=memory_store, attributes={"foo": "bar"})
520-
read_store = zarr.store.MemoryStore(store_dict=memory_store._store_dict)
521-
with pytest.raises(ValueError, match="does not support writing"):
522-
await consolidate_metadata(read_store)
523-
524-
async def test_non_root_node(self, memory_store_with_hierarchy: Store) -> None:
525-
await consolidate_metadata(memory_store_with_hierarchy, path="child")
526-
root = await AsyncGroup.open(memory_store_with_hierarchy)
527-
child = await AsyncGroup.open(StorePath(memory_store_with_hierarchy) / "child")
528-
529-
assert root.metadata.consolidated_metadata is None
530-
assert child.metadata.consolidated_metadata is not None
531-
assert "air" not in child.metadata.consolidated_metadata.metadata
532-
assert "grandchild" in child.metadata.consolidated_metadata.metadata

0 commit comments

Comments
 (0)