Skip to content

Commit 053731e

Browse files
committed
test(zarr-metadata): cover scale_offset over a data type the package does not define
The identity configuration `scale_offset` draws for a data type the package does not define had no test, since the chunk test draws only the package's own data types. A test now reads an extension `bfloat16` in a scope of its own and checks the codec takes every draw. Also splits the `_scope_of` error message across two literals and drops a doubled blank line in `_data_type`. Assisted-by: ClaudeCode:claude-opus-5-5
1 parent 804d226 commit 053731e

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎packages/zarr-metadata/src/zarr_metadata/testing/_data_type.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
}
7171
"""The width in bits of each part of each complex data type."""
7272

73-
7473
_MAX_RAW_BYTES: Final = 32
7574
"""The widest raw bits drawn, in bytes: `r256`."""
7675

‎packages/zarr-metadata/src/zarr_metadata/testing/strategies.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ def _scope_of(definition: Definition[Any]) -> ZarrV3Context:
218218
for slot, kind in ZarrV3Context.kinds.items():
219219
if isinstance(definition, kind):
220220
return ZarrV3Context(**cast("ZarrV3ContextSlots", {slot: (definition,)}))
221-
msg = f"{definition.name!r} is a {type(definition).__name__}, which no slot of a Zarr v3 scope holds"
221+
msg = (
222+
f"{definition.name!r} is a {type(definition).__name__}, "
223+
"which no slot of a Zarr v3 scope holds"
224+
)
222225
raise TypeError(msg)
223226

224227

‎packages/zarr-metadata/tests/testing/test_strategies.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from zarr_metadata.definition import (
2525
AcceptedField,
2626
Definition,
27+
EmptyConfiguration,
2728
fill_value_problems,
2829
resolve,
2930
)
@@ -63,6 +64,7 @@
6364
ChunkGridDefinition,
6465
CodecDefinition,
6566
DataTypeDefinition,
67+
ZarrV3Context,
6668
)
6769

6870
if TYPE_CHECKING:
@@ -311,6 +313,25 @@ def test_a_refused_draw_is_a_value_error(spellings: Spellings) -> None:
311313
find(refused, lambda _field: True, settings=settings(database=None))
312314

313315

316+
_BFLOAT16 = DataTypeDefinition(name="bfloat16", configuration=EmptyConfiguration)
317+
"""A number type this package does not define, as an extension author would."""
318+
319+
320+
@given(data=st.data())
321+
def test_scale_offset_takes_a_data_type_the_package_does_not_define(data: st.DataObject) -> None:
322+
"""Values of a type the package does not define cannot be drawn, so the configuration is the identity, which its rules take."""
323+
data_type, problems = resolve(
324+
"bfloat16", DataTypeDefinition, ZarrV3Context(data_types=[_BFLOAT16])
325+
)
326+
assert problems == ()
327+
chunk = Chunk(None, data_type)
328+
configurations = codec_configurations(SCALE_OFFSET_CODEC, chunk)
329+
assert configurations is not None
330+
configuration = data.draw(configurations)
331+
assert configuration == {}
332+
assert list(SCALE_OFFSET_CODEC.chunk_rules(configuration, {}, chunk)) == []
333+
334+
314335
def test_a_definition_no_v3_scope_holds_is_a_type_error() -> None:
315336
zlib = CORE_V2.codecs["zlib"]
316337
with pytest.raises(TypeError, match="which no slot of a Zarr v3 scope holds"):

0 commit comments

Comments
 (0)