Skip to content

Commit 065c363

Browse files
AnsahMohammadahal
authored andcommitted
test: extended util_schema_test to include test_optionally_keyed_by_mulitple_keys
Signed-off-by: AnsahMohammad <mohdansah10@gmail.com>
1 parent 2c01705 commit 065c363

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/test_util_schema.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,20 @@ def test_optionally_keyed_by():
233233

234234
with pytest.raises(MultipleInvalid):
235235
validator({"by-bar": {"a": "b"}})
236+
237+
238+
def test_optionally_keyed_by_mulitple_keys():
239+
validator = optionally_keyed_by("foo", "bar", str)
240+
assert validator("baz") == "baz"
241+
assert validator({"by-foo": {"a": "b", "c": "d"}}) == {"a": "b", "c": "d"}
242+
assert validator({"by-bar": {"x": "y"}}) == {"x": "y"}
243+
assert validator({"by-foo": {"a": {"by-bar": {"x": "y"}}}}) == {"a": {"x": "y"}}
244+
245+
with pytest.raises(Invalid):
246+
validator({"by-foo": {"a": 123, "c": "d"}})
247+
248+
with pytest.raises(MultipleInvalid):
249+
validator({"by-bar": {"a": 1}})
250+
251+
with pytest.raises(MultipleInvalid):
252+
validator({"by-unknown": {"a": "b"}})

0 commit comments

Comments
 (0)