Skip to content

Commit a1d3520

Browse files
committed
test_constant_map
1 parent ec5f396 commit a1d3520

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

zarr/tests/test_util.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from zarr.core import Array
8-
from zarr.util import (all_equal, flatten, guess_chunks, human_readable_size,
8+
from zarr.util import (ConstantMap, all_equal, flatten, guess_chunks, human_readable_size,
99
info_html_report, info_text_report, is_total_slice,
1010
json_dumps, normalize_chunks,
1111
normalize_dimension_separator,
@@ -248,3 +248,16 @@ def test_json_dumps_numpy_dtype():
248248
# Check that we raise the error of the superclass for unsupported object
249249
with pytest.raises(TypeError):
250250
json_dumps(Array)
251+
252+
253+
def test_constant_map():
254+
val = object()
255+
m = ConstantMap(keys=[1, 2], constant=val)
256+
assert len(m) == 2
257+
assert m[1] is val
258+
assert m[2] is val
259+
assert 1 in m
260+
assert 0 not in m
261+
with pytest.raises(KeyError):
262+
m[0]
263+
assert repr(m) == repr({1: val, 2: val})

0 commit comments

Comments
 (0)