From a1d3520f33528df09ebb58bdb5659b7ccb2ca589 Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Tue, 11 Apr 2023 14:14:49 +0200 Subject: [PATCH] test_constant_map --- zarr/tests/test_util.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/zarr/tests/test_util.py b/zarr/tests/test_util.py index e9e1786abe..0a717b8f28 100644 --- a/zarr/tests/test_util.py +++ b/zarr/tests/test_util.py @@ -5,7 +5,7 @@ import pytest from zarr.core import Array -from zarr.util import (all_equal, flatten, guess_chunks, human_readable_size, +from zarr.util import (ConstantMap, all_equal, flatten, guess_chunks, human_readable_size, info_html_report, info_text_report, is_total_slice, json_dumps, normalize_chunks, normalize_dimension_separator, @@ -248,3 +248,16 @@ def test_json_dumps_numpy_dtype(): # Check that we raise the error of the superclass for unsupported object with pytest.raises(TypeError): json_dumps(Array) + + +def test_constant_map(): + val = object() + m = ConstantMap(keys=[1, 2], constant=val) + assert len(m) == 2 + assert m[1] is val + assert m[2] is val + assert 1 in m + assert 0 not in m + with pytest.raises(KeyError): + m[0] + assert repr(m) == repr({1: val, 2: val})