Skip to content

Commit

Permalink
use right operand to check NotImplemnted branch
Browse files Browse the repository at this point in the history
Signed-off-by: a5r0n <a5r0n@users.noreply.github.com>
  • Loading branch information
a5r0n committed Feb 1, 2024
1 parent a2b9578 commit be3bc62
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions tests/test_multidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Dict,
Iterable,
Iterator,
KeysView,
List,
Mapping,
Set,
Expand Down Expand Up @@ -390,8 +391,14 @@ def test_and2(self, cls: Type[MutableMultiMapping[str]]) -> None:
def test_and_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1")])

with pytest.raises(TypeError, match=r"unsupported operand type(\(s\))? for \&"):
d.keys() & 1
sentinel_operation_result = object()

class RightOperand:
def __rand__(self, other):
assert isinstance(other, KeysView)
return sentinel_operation_result

assert d.keys() & RightOperand() is sentinel_operation_result

def test_and_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1")])
Expand All @@ -411,8 +418,14 @@ def test_or2(self, cls: Type[MutableMultiMapping[str]]) -> None:
def test_or_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1")])

with pytest.raises(TypeError, match=r"unsupported operand type(\(s\))? for \|"):
d.keys() | 1
sentinel_operation_result = object()

class RightOperand:
def __ror__(self, other):
assert isinstance(other, KeysView)
return sentinel_operation_result

assert d.keys() | RightOperand() is sentinel_operation_result

def test_or_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1")])
Expand All @@ -432,8 +445,14 @@ def test_sub2(self, cls: Type[MutableMultiMapping[str]]) -> None:
def test_sub_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1"), ("key2", "value2")])

with pytest.raises(TypeError, match=r"unsupported operand type(\(s\))? for -"):
d.keys() - 1
sentinel_operation_result = object()

class RightOperand:
def __rsub__(self, other):
assert isinstance(other, KeysView)
return sentinel_operation_result

assert d.keys() - RightOperand() is sentinel_operation_result

def test_sub_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1"), ("key2", "value2")])
Expand All @@ -453,8 +472,14 @@ def test_xor2(self, cls: Type[MutableMultiMapping[str]]) -> None:
def test_xor_not_implemented(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1"), ("key2", "value2")])

with pytest.raises(TypeError, match=r"unsupported operand type(\(s\))? for \^"):
d.keys() ^ 1
sentinel_operation_result = object()

class RightOperand:
def __rxor__(self, other):
assert isinstance(other, KeysView)
return sentinel_operation_result

assert d.keys() ^ RightOperand() is sentinel_operation_result

def test_xor_iterable_not_set(self, cls: Type[MutableMultiMapping[str]]) -> None:
d = cls([("key", "value1"), ("key2", "value2")])
Expand Down

0 comments on commit be3bc62

Please sign in to comment.