This commit is contained in:
jab 2018-02-19 09:16:09 +00:00
parent 5cc0af2623
commit d57bae234f
1 changed files with 5 additions and 4 deletions

View File

@ -70,8 +70,11 @@ not_bidicts = (
@pytest.mark.parametrize('b, other', product(bidicts, bidicts + not_bidicts)) @pytest.mark.parametrize('b, other', product(bidicts, bidicts + not_bidicts))
def test_eq_and_hash(b, other): def test_eq_and_hash(b, other):
"""Make sure equality tests and hash results behave as expected.""" """Make sure equality tests and hash results behave as expected."""
b_has_eq_order_sens = hasattr(b, 'equals_order_sensitive')
if not isinstance(other, Mapping): if not isinstance(other, Mapping):
assert b != other assert b != other
if b_has_eq_order_sens:
assert not b.equals_order_sensitive(other)
elif len(b) != len(other): elif len(b) != len(other):
assert b != other assert b != other
else: else:
@ -81,9 +84,7 @@ def test_eq_and_hash(b, other):
both_hashable = isinstance(b, Hashable) and isinstance(other, Hashable) both_hashable = isinstance(b, Hashable) and isinstance(other, Hashable)
if are_equal and both_hashable: if are_equal and both_hashable:
assert hash(b) == hash(other) assert hash(b) == hash(other)
if b_has_eq_order_sens:
if hasattr(b, 'equals_order_sensitive'):
are_equal_ordered = b.equals_order_sensitive(other) are_equal_ordered = b.equals_order_sensitive(other)
should_be_equal_ordered = OrderedDict(b) == ( should_be_equal_ordered = OrderedDict(b) == OrderedDict(other)
OrderedDict(other) if isinstance(other, Mapping) else other)
assert are_equal_ordered == should_be_equal_ordered assert are_equal_ordered == should_be_equal_ordered