mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Changed msg.<html/md>_text attributes behaviour
This commit is contained in:
parent
bc20999429
commit
fa9abfdbef
4 changed files with 12 additions and 17 deletions
2
CHANGES/874.misc.rst
Normal file
2
CHANGES/874.misc.rst
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Changed :code:`Message.html_text` and :code:`Message.md_text` attributes behaviour when message has no text.
|
||||
The empty string will be used instead of raising error.
|
||||
1
CHANGES/885.bugfix.rst
Normal file
1
CHANGES/885.bugfix.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fixed CallbackData factory parsing IntEnum's
|
||||
|
|
@ -267,11 +267,8 @@ class Message(_BaseMessage):
|
|||
return ContentType.UNKNOWN
|
||||
|
||||
def _unparse_entities(self, text_decoration: TextDecoration) -> str:
|
||||
text = self.text or self.caption
|
||||
if text is None:
|
||||
raise TypeError("This message doesn't have any text.")
|
||||
|
||||
entities = self.entities or self.caption_entities
|
||||
text = self.text or self.caption or ""
|
||||
entities = self.entities or self.caption_entities or []
|
||||
return text_decoration.unparse(text=text, entities=entities)
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -641,13 +641,15 @@ class TestMessage:
|
|||
assert method.message_id == message.message_id
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text,entities,correct",
|
||||
"text,entities,mode,expected_value",
|
||||
[
|
||||
["test", [MessageEntity(type="bold", offset=0, length=4)], True],
|
||||
["", [], False],
|
||||
["test", [MessageEntity(type="bold", offset=0, length=4)], "html", "<b>test</b>"],
|
||||
["test", [MessageEntity(type="bold", offset=0, length=4)], "md", "*test*"],
|
||||
["", [], "html", ""],
|
||||
["", [], "md", ""],
|
||||
],
|
||||
)
|
||||
def test_html_text(self, text, entities, correct):
|
||||
def test_html_text(self, text, entities, mode, expected_value):
|
||||
message = Message(
|
||||
message_id=42,
|
||||
chat=Chat(id=42, type="private"),
|
||||
|
|
@ -655,11 +657,4 @@ class TestMessage:
|
|||
text=text,
|
||||
entities=entities,
|
||||
)
|
||||
if correct:
|
||||
assert message.html_text
|
||||
assert message.md_text
|
||||
else:
|
||||
with pytest.raises(TypeError):
|
||||
assert message.html_text
|
||||
with pytest.raises(TypeError):
|
||||
assert message.md_text
|
||||
assert getattr(message, f"{mode}_text") == expected_value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue