File: test_inputsticker.py

package info (click to toggle)
python-telegram-bot 22.3-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,060 kB
  • sloc: python: 90,298; makefile: 176; sh: 4
file content (83 lines) | stat: -rw-r--r-- 3,521 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2025
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program.  If not, see [http://www.gnu.org/licenses/].

import pytest

from telegram import InputSticker, MaskPosition
from telegram._files.inputfile import InputFile
from tests.auxil.files import data_file
from tests.auxil.slots import mro_slots


@pytest.fixture(scope="module")
def input_sticker():
    return InputSticker(
        sticker=InputStickerTestBase.sticker,
        emoji_list=InputStickerTestBase.emoji_list,
        mask_position=InputStickerTestBase.mask_position,
        keywords=InputStickerTestBase.keywords,
        format=InputStickerTestBase.format,
    )


class InputStickerTestBase:
    sticker = "fake_file_id"
    emoji_list = ("👍", "👎")
    mask_position = MaskPosition("forehead", 0.5, 0.5, 0.5)
    keywords = ("thumbsup", "thumbsdown")
    format = "static"


class TestInputStickerWithoutRequest(InputStickerTestBase):
    def test_slot_behaviour(self, input_sticker):
        inst = input_sticker
        for attr in inst.__slots__:
            assert getattr(inst, attr, "err") != "err", f"got extra slot '{attr}'"
        assert len(mro_slots(inst)) == len(set(mro_slots(inst))), "duplicate slot"

    def test_expected_values(self, input_sticker):
        assert input_sticker.sticker == self.sticker
        assert isinstance(input_sticker.sticker, str)
        assert input_sticker.emoji_list == self.emoji_list
        assert input_sticker.mask_position == self.mask_position
        assert input_sticker.keywords == self.keywords
        assert input_sticker.format == self.format

    def test_attributes_tuple(self, input_sticker):
        assert isinstance(input_sticker.keywords, tuple)
        assert isinstance(input_sticker.emoji_list, tuple)
        a = InputSticker("sticker", ["emoji"], "static")
        assert isinstance(a.emoji_list, tuple)
        assert a.keywords == ()

    def test_to_dict(self, input_sticker):
        input_sticker_dict = input_sticker.to_dict()

        assert isinstance(input_sticker_dict, dict)
        assert input_sticker_dict["sticker"] == input_sticker.sticker
        assert input_sticker_dict["emoji_list"] == list(input_sticker.emoji_list)
        assert input_sticker_dict["mask_position"] == input_sticker.mask_position.to_dict()
        assert input_sticker_dict["keywords"] == list(input_sticker.keywords)
        assert input_sticker_dict["format"] == input_sticker.format

    def test_with_sticker_input_types(self, video_sticker_file):
        sticker = InputSticker(sticker=video_sticker_file, emoji_list=["👍"], format="video")
        assert isinstance(sticker.sticker, InputFile)
        sticker = InputSticker(data_file("telegram_video_sticker.webm"), ["👍"], "video")
        assert sticker.sticker == data_file("telegram_video_sticker.webm").as_uri()