Skip to content

Make MessageEntity objects comparable #1465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions telegram/messageentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def __init__(self, type, offset, length, url=None, user=None, **kwargs):
self.url = url
self.user = user

self._id_attrs = (self.type, self.offset, self.length)

@classmethod
def de_json(cls, data, bot):
data = super(MessageEntity, cls).de_json(data, bot)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_messageentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,19 @@ def test_to_dict(self, message_entity):
assert entity_dict['url'] == message_entity.url
if message_entity.user:
assert entity_dict['user'] == message_entity.user.to_dict()

def test_equality(self):
a = MessageEntity(MessageEntity.BOLD, 2, 3)
b = MessageEntity(MessageEntity.BOLD, 2, 3)
c = MessageEntity(MessageEntity.CODE, 2, 3)
d = MessageEntity(MessageEntity.CODE, 5, 6)

assert a == b
assert hash(a) == hash(b)
assert a is not b

assert a != c
assert hash(a) != hash(c)

assert a != d
assert hash(a) != hash(d)