Improve Code Quality & Test Suite ()

This commit is contained in:
Harshil 2022-01-09 14:47:16 +04:00 committed by Hinrich Mahler
parent 9354db7c19
commit f4147fb583
3 changed files with 25 additions and 28 deletions

View file

@ -2533,20 +2533,20 @@ class Message(TelegramObject):
elif entity.type == MessageEntity.URL and urled:
insert = f'<a href="{text}">{text}</a>'
elif entity.type == MessageEntity.BOLD:
insert = '<b>' + text + '</b>'
insert = f'<b>{text}</b>'
elif entity.type == MessageEntity.ITALIC:
insert = '<i>' + text + '</i>'
insert = f'<i>{text}</i>'
elif entity.type == MessageEntity.CODE:
insert = '<code>' + text + '</code>'
insert = f'<code>{text}</code>'
elif entity.type == MessageEntity.PRE:
if entity.language:
insert = f'<pre><code class="{entity.language}">{text}</code></pre>'
else:
insert = '<pre>' + text + '</pre>'
insert = f'<pre>{text}</pre>'
elif entity.type == MessageEntity.UNDERLINE:
insert = '<u>' + text + '</u>'
insert = f'<u>{text}</u>'
elif entity.type == MessageEntity.STRIKETHROUGH:
insert = '<s>' + text + '</s>'
insert = f'<s>{text}</s>'
elif entity.type == MessageEntity.SPOILER:
insert = f'<span class="tg-spoiler">{text}</span>'
else:
@ -2697,7 +2697,7 @@ class Message(TelegramObject):
if nested_entities:
if version < 2:
raise ValueError(
'Nested entities are not supported for Markdown ' 'version 1'
'Nested entities are not supported for Markdown version 1'
)
text = Message._parse_markdown(
@ -2726,43 +2726,38 @@ class Message(TelegramObject):
link = text
insert = f'[{link}]({orig_text})'
elif entity.type == MessageEntity.BOLD:
insert = '*' + text + '*'
insert = f'*{text}*'
elif entity.type == MessageEntity.ITALIC:
insert = '_' + text + '_'
insert = f'_{text}_'
elif entity.type == MessageEntity.CODE:
# Monospace needs special escaping. Also can't have entities nested within
insert = (
'`'
+ escape_markdown(
orig_text, version=version, entity_type=MessageEntity.CODE
)
+ '`'
)
insert = f'`{escape_markdown(orig_text, version, MessageEntity.CODE)}`'
elif entity.type == MessageEntity.PRE:
# Monospace needs special escaping. Also can't have entities nested within
code = escape_markdown(
orig_text, version=version, entity_type=MessageEntity.PRE
)
if entity.language:
prefix = '```' + entity.language + '\n'
prefix = f'```{entity.language}\n'
else:
if code.startswith('\\'):
prefix = '```'
else:
prefix = '```\n'
insert = prefix + code + '```'
insert = f'{prefix}{code}```'
elif entity.type == MessageEntity.UNDERLINE:
if version == 1:
raise ValueError(
'Underline entities are not supported for Markdown ' 'version 1'
'Underline entities are not supported for Markdown version 1'
)
insert = '__' + text + '__'
insert = f'__{text}__'
elif entity.type == MessageEntity.STRIKETHROUGH:
if version == 1:
raise ValueError(
'Strikethrough entities are not supported for Markdown ' 'version 1'
'Strikethrough entities are not supported for Markdown version 1'
)
insert = '~' + text + '~'
insert = f'~{text}~'
elif entity.type == MessageEntity.SPOILER:
if version == 1:
raise ValueError(

View file

@ -18,12 +18,14 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
# pylint: disable=no-self-use
"""This module contains the auxiliary class ContextTypes."""
from typing import Type, Generic, overload, Dict # pylint: disable=unused-import
from typing import Type, Generic, overload, Dict, TYPE_CHECKING # pylint: disable=unused-import
from telegram.ext._callbackcontext import CallbackContext
from telegram.ext._extbot import ExtBot # pylint: disable=unused-import
from telegram.ext._utils.types import CCT, UD, CD, BD
if TYPE_CHECKING:
from telegram.ext._extbot import ExtBot # pylint: disable=unused-import
class ContextTypes(Generic[CCT, UD, CD, BD]):
"""

View file

@ -615,13 +615,13 @@ class TestUpdater:
# (bots) running simultaneously while testing in github actions.
records = caplog.records.copy() # To avoid iterating and removing at same time
for idx, log in enumerate(records):
print(log)
print(idx, log)
msg = log.getMessage()
if msg.startswith('Error while getting Updates: Conflict'):
caplog.records.pop(idx) # For stability
caplog.records.remove(log) # For stability
if msg.startswith('No error handlers are registered'):
caplog.records.pop(idx)
elif msg.startswith('No error handlers are registered'):
caplog.records.remove(log)
assert len(caplog.records) == 2, caplog.records