From 5b96b9b11850ab312d0ee2fabaca029d3c2e9bc4 Mon Sep 17 00:00:00 2001 From: A_D Date: Tue, 10 Aug 2021 12:21:51 +0200 Subject: [PATCH] tests for _apply complete --- tests/killswitch.py/test_apply.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/killswitch.py/test_apply.py b/tests/killswitch.py/test_apply.py index c3c97cb7..bd7bdfd3 100644 --- a/tests/killswitch.py/test_apply.py +++ b/tests/killswitch.py/test_apply.py @@ -25,13 +25,27 @@ def test_apply(source: UPDATABLE_DATA, key: str, action: str, to_set: Any, resul assert cpy == result -def test_apply_keyerror() -> None: +def test_apply_errors() -> None: """_apply should fail when passed something that isn't a Sequence or MutableMapping.""" with pytest.raises(ValueError, match=r'Dont know how to'): killswitch._apply(set(), "0", None, False) # type: ignore # Its intentional that its broken killswitch._apply(None, "", None) # type: ignore # Its intentional that its broken +def test_apply_no_error() -> None: + """ + _apply should not raise when deleting keys that dont exist, nor should it raise on setting keys that dont exist. + + The only exception here is for lists. if a list is malformed to what a killswitch expects, it SHOULD explode, + thus causing the killswitch to fail and eat the entire message. + """ + killswitch._apply([], "0", None, True) + killswitch._apply({}, "0", None, True) + killswitch._apply({}, "this doesn't exist", None, True) + with pytest.raises(IndexError): + killswitch._apply([], "1", "bang?") + + @pytest.mark.parametrize( ("input", "expected"), [