Skip to content

Commit

Permalink
Add extra key_error test conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak committed Jan 19, 2024
1 parent 6e228ac commit 6e2772b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def test_to_dict():
assert to_dict("a", {"a": "first", "b": "second"}) == {"a": "first", "b": "second"}
assert to_dict("a", {"a": "first", "b": "%s"}) == {"a": "first", "b": "a"}
assert to_dict("a", {"%s_1": "first", "%s_2": "%s"}) == {"a_1": "first", "a_2": "a"}
assert to_dict("a", {"%s_1": "first", "%s_2": "%s"}) == {"a_1": "first", "a_2": "a"}


def test_map_format():
Expand Down Expand Up @@ -161,6 +162,14 @@ def test_key_item():
d = {"a": "first", "b": "second"}
assert key_item(d, "a") == ["first", {"b": "second"}]
assert key_item(d, "b") == ["second", {"a": "first"}]
e = {"b": "second"}
f = {"a": e}
assert key_item(f, ["a", "b"], False) == ["second", f]
assert key_item(f, ["a"], False) == [e, f]
with pytest.raises(KeyError):
key_item(d, ["na"], False)
with pytest.raises(ValueError):
key_item(d, ["na"])


def test_dict_to_list():
Expand All @@ -179,6 +188,18 @@ def test_list_to_dict():
"a": {"content": "first", "key": "a"},
"b": {"content": "second", "key": "b"},
}
e = [
{"a": {"b": "first"}},
{"a": {"b": "second"}},
]
assert list_to_dict(e, ["a", "b"], False) == {
"first": {"a": {"b": "first"}},
"second": {"a": {"b": "second"}}
}
with pytest.raises(KeyError):
list_to_dict(e, ["a", "c"], False)
with pytest.raises(ValueError):
list_to_dict(e, ["a", "c"])


def test_to_kv():
Expand Down

0 comments on commit 6e2772b

Please sign in to comment.