From 1aad5a1c6df1a8f8ac1817b0f806bf9d99f06adb Mon Sep 17 00:00:00 2001 From: a5r0n Date: Wed, 31 Jan 2024 12:46:35 +0200 Subject: [PATCH] Add test coverage for _multidict_base.py `NotImplemented` and `Iterable` but not `Set` for `and, or, sub, xor` --- tests/test_multidict.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_multidict.py b/tests/test_multidict.py index 4012a5692..4da676547 100644 --- a/tests/test_multidict.py +++ b/tests/test_multidict.py @@ -387,6 +387,17 @@ def test_and2(self, cls: Type[MutableMultiMapping[str]]) -> None: assert {"key"} == {"key", "key2"} & d.keys() + def test_and_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1")]) + + with pytest.raises(TypeError): + operator.and_(d.keys(), 1) + + def test_and_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1")]) + + assert {"key"} == d.keys() & ["key", "key2"] + def test_or(self, cls: Type[MutableMultiMapping[str]]) -> None: d = cls([("key", "value1")]) @@ -397,6 +408,17 @@ def test_or2(self, cls: Type[MutableMultiMapping[str]]) -> None: assert {"key", "key2"} == {"key2"} | d.keys() + def test_or_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1")]) + + with pytest.raises(TypeError): + operator.or_(d.keys(), 1) + + def test_or_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1")]) + + assert {"key", "key2"} == d.keys() | ["key2"] + def test_sub(self, cls: Type[MutableMultiMapping[str]]) -> None: d = cls([("key", "value1"), ("key2", "value2")]) @@ -407,6 +429,17 @@ def test_sub2(self, cls: Type[MutableMultiMapping[str]]) -> None: assert {"key3"} == {"key", "key2", "key3"} - d.keys() + def test_sub_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1"), ("key2", "value2")]) + + with pytest.raises(TypeError): + operator.sub(d.keys(), 1) + + def test_sub_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1"), ("key2", "value2")]) + + assert {"key"} == d.keys() - ["key2"] + def test_xor(self, cls: Type[MutableMultiMapping[str]]) -> None: d = cls([("key", "value1"), ("key2", "value2")]) @@ -417,6 +450,17 @@ def test_xor2(self, cls: Type[MutableMultiMapping[str]]) -> None: assert {"key", "key3"} == {"key2", "key3"} ^ d.keys() + def test_xor_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1"), ("key2", "value2")]) + + with pytest.raises(TypeError): + operator.xor(d.keys(), 1) + + def test_xor_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None: + d = cls([("key", "value1"), ("key2", "value2")]) + + assert {"key", "key3"} == d.keys() ^ ["key2", "key3"] + @pytest.mark.parametrize( ("key", "value", "expected"), (("key2", "v", True), ("key", "value1", False)),