Telethon/client/tests/peer_ref_test.py

42 lines
935 B
Python
Raw Normal View History

2024-03-18 20:55:23 +03:00
import inspect
from pytest import raises
2024-03-18 20:55:23 +03:00
from telethon._impl.session import ChannelRef, GroupRef, PeerRef, UserRef
USER = UserRef(12, 34)
GROUP = GroupRef(5, None)
CHANNEL = ChannelRef(67, 89)
def test_peer_ref() -> None:
assert PeerRef.from_str(str(USER)) == USER
assert PeerRef.from_str(str(GROUP)) == GROUP
assert PeerRef.from_str(str(CHANNEL)) == CHANNEL
assert inspect.isabstract(PeerRef)
with raises(ValueError):
PeerRef.from_str("invalid")
def test_user_ref() -> None:
assert UserRef.from_str(str(USER)) == USER
with raises(TypeError):
UserRef.from_str(str(GROUP))
def test_group_ref() -> None:
assert GroupRef.from_str(str(GROUP)) == GROUP
with raises(TypeError):
GroupRef.from_str(str(CHANNEL))
def test_channel_ref() -> None:
assert ChannelRef.from_str(str(CHANNEL)) == CHANNEL
with raises(TypeError):
ChannelRef.from_str(str(USER))