Skip to content

Commit f0300d1

Browse files
committed
add tests for single-argument templated exceptions
1 parent ce4aa18 commit f0300d1

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/test_errors.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Test errors"""
2+
3+
from zarr.errors import (
4+
ArrayNotFoundError,
5+
ContainsArrayAndGroupError,
6+
ContainsArrayError,
7+
ContainsGroupError,
8+
GroupNotFoundError,
9+
MetadataValidationError,
10+
NodeTypeValidationError,
11+
)
12+
13+
14+
def test_group_not_found_error() -> None:
15+
"""
16+
Test that calling GroupNotFoundError with multiple arguments returns a formatted string.
17+
This is deprecated behavior.
18+
"""
19+
err = GroupNotFoundError("store", "path")
20+
assert str(err) == "No group found in store 'store' at path 'path'"
21+
22+
23+
def test_array_not_found_error() -> None:
24+
"""
25+
Test that calling ArrayNotFoundError with multiple arguments returns a formatted string.
26+
This is deprecated behavior.
27+
"""
28+
err = ArrayNotFoundError("store", "path")
29+
assert str(err) == "No array found in store 'store' at path 'path'"
30+
31+
32+
def test_metadata_validation_error() -> None:
33+
"""
34+
Test that calling MetadataValidationError with multiple arguments returns a formatted string.
35+
This is deprecated behavior.
36+
"""
37+
err = MetadataValidationError("a", "b", "c")
38+
assert str(err) == "Invalid value for 'a'. Expected 'b'. Got 'c'."
39+
40+
41+
def test_contains_group_error() -> None:
42+
"""
43+
Test that calling ContainsGroupError with multiple arguments returns a formatted string.
44+
This is deprecated behavior.
45+
"""
46+
err = ContainsGroupError("store", "path")
47+
assert str(err) == "A group exists in store 'store' at path 'path'."
48+
49+
50+
def test_contains_array_error() -> None:
51+
"""
52+
Test that calling ContainsArrayError with multiple arguments returns a formatted string.
53+
This is deprecated behavior.
54+
"""
55+
err = ContainsArrayError("store", "path")
56+
assert str(err) == "An array exists in store 'store' at path 'path'."
57+
58+
59+
def test_contains_array_and_group_error() -> None:
60+
"""
61+
Test that calling ContainsArrayAndGroupError with multiple arguments returns a formatted string.
62+
This is deprecated behavior.
63+
"""
64+
err = ContainsArrayAndGroupError("store", "path")
65+
assert str(err) == (
66+
"Array and group metadata documents (.zarray and .zgroup) were both found in store 'store' "
67+
"at path 'path'. Only one of these files may be present in a given directory / prefix. "
68+
"Remove the .zarray file, or the .zgroup file, or both."
69+
)
70+
71+
72+
def test_node_type_validation_error() -> None:
73+
"""
74+
Test that calling NodeTypeValidationError with multiple arguments returns a formatted string.
75+
This is deprecated behavior.
76+
"""
77+
err = NodeTypeValidationError("a", "b", "c")
78+
assert str(err) == "Invalid value for 'a'. Expected 'b'. Got 'c'."

0 commit comments

Comments
 (0)