Skip to content

Commit

Permalink
test: codify SopelIdentifierMemory == dict behavior
Browse files Browse the repository at this point in the history
Comparing two `SopelIdentifierMemory` instances using `==` already
worked, but if one side of the comparison was a plain `dict` it would
be almost impossible for the two to be considered equal.

It's obviously doable to override `__eq__()`/`__ne__()` and make the two
types test as equal if they have equal values associated with keys-that-
are-equivalent-when-compared-as-`Identifier`s, but we probably shouldn't
do that. I'm perfectly happy to consider objects of different types as
"not equal" even if they contain equivalent key-value pairs.
  • Loading branch information
dgw committed Oct 21, 2023
1 parent 7ead271 commit e6556a7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/tools/test_tools_memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,25 @@ def test_sopel_identifier_memory_ior_op_dict():
assert memory['fROmMemorY'] is True
assert memory['fROmDicT'] is True
assert 'FromTuple' not in memory


def test_sopel_identifier_memory_eq():
"""Test equality checks between two `SopelIdentifierMemory` instances."""
memory = memories.SopelIdentifierMemory({'Foo': 'bar', 'Baz': 'Luhrmann'})
other_memory = memories.SopelIdentifierMemory((('Foo', 'bar'), ('Baz', 'Luhrmann')))

assert memory == other_memory
assert other_memory == memory # cover our bases vis-a-vis operand precedence


def test_sopel_identifier_memory_eq_dict():
"""Test equality checks between `dict` and `SopelIdentifierMemory`.
Sopel's memory types are actually NOT guaranteed to compare as identical
with a `dict` containing the same key-value pairs.
"""
dictionary = {'Foo': 'bar', 'Baz': 'Luhrmann'}
memory = memories.SopelIdentifierMemory(dictionary)

assert dictionary != memory
assert memory != dictionary # cover our bases vis-a-vis operand precedence

0 comments on commit e6556a7

Please sign in to comment.