mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-26 16:38:53 +01:00
Update pre-commit Settings & Improve a Test (#2796)
This commit is contained in:
parent
28c8c155ce
commit
9b56be44b4
12 changed files with 22 additions and 22 deletions
|
@ -14,12 +14,14 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
- repo: https://github.com/PyCQA/pylint
|
- repo: https://github.com/PyCQA/pylint
|
||||||
rev: v2.11.1
|
rev: v2.12.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
files: ^(telegram|examples)/.*\.py$
|
files: ^(telegram|examples)/.*\.py$
|
||||||
args:
|
args:
|
||||||
- --rcfile=setup.cfg
|
- --rcfile=setup.cfg
|
||||||
|
# run pylint across multiple cpu cores to speed it up-
|
||||||
|
- --jobs=0 # See https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- certifi
|
- certifi
|
||||||
- tornado>=6.1
|
- tornado>=6.1
|
||||||
|
|
|
@ -5,7 +5,7 @@ pre-commit
|
||||||
# Make sure that the versions specified here match the pre-commit settings!
|
# Make sure that the versions specified here match the pre-commit settings!
|
||||||
black==21.9b0
|
black==21.9b0
|
||||||
flake8==4.0.1
|
flake8==4.0.1
|
||||||
pylint==2.11.1
|
pylint==2.12.1
|
||||||
mypy==0.910
|
mypy==0.910
|
||||||
pyupgrade==2.29.0
|
pyupgrade==2.29.0
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ class CallbackQuery(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str, # pylint: disable=redefined-builtin
|
id: str, # pylint: disable=invalid-name
|
||||||
from_user: User,
|
from_user: User,
|
||||||
chat_instance: str,
|
chat_instance: str,
|
||||||
message: Message = None,
|
message: Message = None,
|
||||||
|
|
|
@ -204,7 +204,7 @@ class Chat(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: int,
|
id: int, # pylint: disable=invalid-name
|
||||||
type: str,
|
type: str,
|
||||||
title: str = None,
|
title: str = None,
|
||||||
username: str = None,
|
username: str = None,
|
||||||
|
|
|
@ -75,7 +75,7 @@ class InlineQuery(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str, # pylint: disable=redefined-builtin
|
id: str, # pylint: disable=redefined-builtin, invalid-name
|
||||||
from_user: User,
|
from_user: User,
|
||||||
query: str,
|
query: str,
|
||||||
offset: str,
|
offset: str,
|
||||||
|
|
|
@ -48,7 +48,7 @@ class InlineQueryResult(TelegramObject):
|
||||||
|
|
||||||
__slots__ = ('type', 'id')
|
__slots__ = ('type', 'id')
|
||||||
|
|
||||||
def __init__(self, type: str, id: str, **_kwargs: Any):
|
def __init__(self, type: str, id: str, **_kwargs: Any): # pylint: disable=invalid-name
|
||||||
# Required
|
# Required
|
||||||
self.type = type
|
self.type = type
|
||||||
self.id = str(id) # pylint: disable=invalid-name
|
self.id = str(id) # pylint: disable=invalid-name
|
||||||
|
|
|
@ -79,7 +79,7 @@ class PreCheckoutQuery(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str, # pylint: disable=redefined-builtin
|
id: str, # pylint: disable=redefined-builtin, invalid-name
|
||||||
from_user: User,
|
from_user: User,
|
||||||
currency: str,
|
currency: str,
|
||||||
total_amount: int,
|
total_amount: int,
|
||||||
|
|
|
@ -50,7 +50,7 @@ class ShippingOption(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str, # pylint: disable=redefined-builtin
|
id: str, # pylint: disable=redefined-builtin, invalid-name
|
||||||
title: str,
|
title: str,
|
||||||
prices: List['LabeledPrice'],
|
prices: List['LabeledPrice'],
|
||||||
**_kwargs: Any,
|
**_kwargs: Any,
|
||||||
|
|
|
@ -58,7 +58,7 @@ class ShippingQuery(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str, # pylint: disable=redefined-builtin
|
id: str, # pylint: disable=redefined-builtin, invalid-name
|
||||||
from_user: User,
|
from_user: User,
|
||||||
invoice_payload: str,
|
invoice_payload: str,
|
||||||
shipping_address: ShippingAddress,
|
shipping_address: ShippingAddress,
|
||||||
|
|
|
@ -168,7 +168,7 @@ class Poll(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: str, # pylint: disable=redefined-builtin
|
id: str, # pylint: disable=redefined-builtin, invalid-name
|
||||||
question: str,
|
question: str,
|
||||||
options: List[PollOption],
|
options: List[PollOption],
|
||||||
total_voter_count: int,
|
total_voter_count: int,
|
||||||
|
|
|
@ -110,7 +110,7 @@ class User(TelegramObject):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: int,
|
id: int, # pylint: disable=invalid-name
|
||||||
first_name: str,
|
first_name: str,
|
||||||
is_bot: bool,
|
is_bot: bool,
|
||||||
last_name: str = None,
|
last_name: str = None,
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser Public License
|
# You should have received a copy of the GNU Lesser Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
import datetime
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import datetime as dtm
|
import datetime as dtm
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from platform import python_implementation
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytz
|
import pytz
|
||||||
|
@ -54,7 +54,7 @@ from telegram import (
|
||||||
)
|
)
|
||||||
from telegram.constants import ChatAction, ParseMode, InlineQueryLimit
|
from telegram.constants import ChatAction, ParseMode, InlineQueryLimit
|
||||||
from telegram.ext import ExtBot, InvalidCallbackData
|
from telegram.ext import ExtBot, InvalidCallbackData
|
||||||
from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter, TelegramError
|
from telegram.error import BadRequest, InvalidToken, NetworkError, TelegramError
|
||||||
from telegram._utils.datetime import from_timestamp, to_timestamp
|
from telegram._utils.datetime import from_timestamp, to_timestamp
|
||||||
from telegram._utils.defaultvalue import DefaultValue
|
from telegram._utils.defaultvalue import DefaultValue
|
||||||
from telegram.helpers import escape_markdown
|
from telegram.helpers import escape_markdown
|
||||||
|
@ -470,10 +470,6 @@ class TestBot:
|
||||||
assert message.has_protected_content
|
assert message.has_protected_content
|
||||||
|
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@pytest.mark.xfail(raises=RetryAfter)
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
python_implementation() == 'PyPy', reason='Unstable on pypy for some reason'
|
|
||||||
)
|
|
||||||
def test_send_contact(self, bot, chat_id):
|
def test_send_contact(self, bot, chat_id):
|
||||||
phone_number = '+11234567890'
|
phone_number = '+11234567890'
|
||||||
first_name = 'Leandro'
|
first_name = 'Leandro'
|
||||||
|
@ -602,7 +598,7 @@ class TestBot:
|
||||||
assert new_message.poll.id == message.poll.id
|
assert new_message.poll.id == message.poll.id
|
||||||
assert new_message.poll.is_closed
|
assert new_message.poll.is_closed
|
||||||
|
|
||||||
@flaky(5, 1)
|
@flaky(3, 1)
|
||||||
def test_send_close_date_default_tz(self, tz_bot, super_group_id):
|
def test_send_close_date_default_tz(self, tz_bot, super_group_id):
|
||||||
question = 'Is this a test?'
|
question = 'Is this a test?'
|
||||||
answers = ['Yes', 'No', 'Maybe']
|
answers = ['Yes', 'No', 'Maybe']
|
||||||
|
@ -613,24 +609,26 @@ class TestBot:
|
||||||
aware_close_date = dtm.datetime.now(tz=tz_bot.defaults.tzinfo) + dtm.timedelta(seconds=5)
|
aware_close_date = dtm.datetime.now(tz=tz_bot.defaults.tzinfo) + dtm.timedelta(seconds=5)
|
||||||
close_date = aware_close_date.replace(tzinfo=None)
|
close_date = aware_close_date.replace(tzinfo=None)
|
||||||
|
|
||||||
message = tz_bot.send_poll(
|
msg = tz_bot.send_poll( # The timezone returned from this is always converted to UTC
|
||||||
chat_id=super_group_id,
|
chat_id=super_group_id,
|
||||||
question=question,
|
question=question,
|
||||||
options=answers,
|
options=answers,
|
||||||
close_date=close_date,
|
close_date=close_date,
|
||||||
timeout=60,
|
timeout=60,
|
||||||
)
|
)
|
||||||
assert message.poll.close_date == aware_close_date.replace(microsecond=0)
|
# Sometimes there can be a few seconds delay, so don't let the test fail due to that-
|
||||||
|
msg.poll.close_date = msg.poll.close_date.astimezone(aware_close_date.tzinfo)
|
||||||
|
assert abs(msg.poll.close_date - aware_close_date) <= datetime.timedelta(seconds=5)
|
||||||
|
|
||||||
time.sleep(5.1)
|
time.sleep(5.1)
|
||||||
|
|
||||||
new_message = tz_bot.edit_message_reply_markup(
|
new_message = tz_bot.edit_message_reply_markup(
|
||||||
chat_id=super_group_id,
|
chat_id=super_group_id,
|
||||||
message_id=message.message_id,
|
message_id=msg.message_id,
|
||||||
reply_markup=reply_markup,
|
reply_markup=reply_markup,
|
||||||
timeout=60,
|
timeout=60,
|
||||||
)
|
)
|
||||||
assert new_message.poll.id == message.poll.id
|
assert new_message.poll.id == msg.poll.id
|
||||||
assert new_message.poll.is_closed
|
assert new_message.poll.is_closed
|
||||||
|
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue