Skip to content

Commit

Permalink
Add test coverage for _multidict_base.py
Browse files Browse the repository at this point in the history
`NotImplemented` and `Iterable` but not `Set` for `and, or, sub, xor`
  • Loading branch information
a5r0n committed Jan 31, 2024
1 parent 61424c1 commit 1aad5a1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_multidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")])

Expand All @@ -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")])

Expand All @@ -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")])

Expand All @@ -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)),
Expand Down

0 comments on commit 1aad5a1

Please sign in to comment.