mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
First run of yapf for tests/* #259
This commit is contained in:
parent
56b1d4f5ce
commit
8ad1f330ea
9 changed files with 60 additions and 51 deletions
|
@ -4,3 +4,4 @@ pep257
|
|||
pylint
|
||||
unittest2
|
||||
flaky
|
||||
yapf
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Base class for tests"""
|
||||
|
||||
import os
|
||||
|
@ -62,7 +61,6 @@ class BaseTest(object):
|
|||
|
||||
|
||||
class TestTimedOut(AssertionError):
|
||||
|
||||
def __init__(self, time_limit, frame):
|
||||
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
|
||||
self.time_limit = time_limit
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Bot"""
|
||||
|
||||
import io
|
||||
|
@ -55,22 +54,26 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendMessage(self):
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
message = self._bot.sendMessage(
|
||||
chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertTrue(isinstance(message.date, datetime))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSilentSendMessage(self):
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
message = self._bot.sendMessage(
|
||||
chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей',
|
||||
disable_notification=True)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertTrue(isinstance(message.date, datetime))
|
||||
|
||||
@flaky(3, 1)
|
||||
|
@ -97,7 +100,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendPhoto(self):
|
||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
||||
message = self._bot.sendPhoto(
|
||||
photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
|
@ -108,7 +112,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSilentSendPhoto(self):
|
||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
||||
message = self._bot.sendPhoto(
|
||||
photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id,
|
||||
disable_notification=True)
|
||||
|
@ -120,16 +125,20 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testResendPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||
message = self._bot.sendPhoto(
|
||||
photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||
self.assertEqual(
|
||||
message.photo[0].file_id,
|
||||
'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendJPGURLPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
|
@ -138,7 +147,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendPNGURLPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
|
@ -147,7 +157,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendGIFURLPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
|
@ -158,8 +169,7 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
def testSendBufferedReaderPhoto(self):
|
||||
photo = open('tests/data/telegram.png', 'rb')
|
||||
br_photo = io.BufferedReader(io.BytesIO(photo.read()))
|
||||
message = self._bot.sendPhoto(photo=br_photo,
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo=br_photo, chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
|
@ -179,7 +189,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(upf.photos[0][0].file_size, 12421)
|
||||
|
||||
def _test_invalid_token(self, token):
|
||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token', telegram.Bot, token)
|
||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token',
|
||||
telegram.Bot, token)
|
||||
|
||||
def testInvalidToken1(self):
|
||||
self._test_invalid_token('123')
|
||||
|
@ -191,12 +202,14 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
self._test_invalid_token('12:')
|
||||
|
||||
def testUnauthToken(self):
|
||||
with self.assertRaisesRegexp(telegram.error.Unauthorized, 'Unauthorized'):
|
||||
with self.assertRaisesRegexp(telegram.error.Unauthorized,
|
||||
'Unauthorized'):
|
||||
bot = telegram.Bot('1234:abcd1234')
|
||||
bot.getMe()
|
||||
|
||||
def testInvalidSrvResp(self):
|
||||
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
|
||||
with self.assertRaisesRegexp(telegram.TelegramError,
|
||||
'Invalid server response'):
|
||||
# bypass the valid token check
|
||||
bot = telegram.Bot.__new__(telegram.Bot)
|
||||
bot.base_url = 'https://api.telegram.org/bot{0}'.format('12')
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Chat"""
|
||||
|
||||
import unittest
|
||||
|
@ -66,5 +65,6 @@ class ChatTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(group_chat['title'], self.title)
|
||||
self.assertEqual(group_chat['type'], self.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Contact"""
|
||||
|
||||
import unittest
|
||||
|
@ -65,5 +64,6 @@ class ContactTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(contact['last_name'], self.last_name)
|
||||
self.assertEqual(contact['user_id'], self.user_id)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Emoji"""
|
||||
|
||||
import unittest
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Location"""
|
||||
|
||||
import unittest
|
||||
|
@ -40,8 +39,7 @@ class LocationTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_send_location_implicit_args(self):
|
||||
message = self._bot.sendLocation(self._chat_id,
|
||||
self.latitude,
|
||||
message = self._bot.sendLocation(self._chat_id, self.latitude,
|
||||
self.longitude)
|
||||
|
||||
location = message.location
|
||||
|
|
|
@ -499,8 +499,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
bootstrap_retries=retries,
|
||||
bootstrap_err=Unauthorized())
|
||||
|
||||
self.assertRaises(Unauthorized, self.updater._bootstrap,
|
||||
retries, False, 'path', None)
|
||||
self.assertRaises(Unauthorized, self.updater._bootstrap, retries,
|
||||
False, 'path', None)
|
||||
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
||||
|
||||
def test_bootstrap_retries_invalid_token(self):
|
||||
|
@ -510,8 +510,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
bootstrap_retries=retries,
|
||||
bootstrap_err=InvalidToken())
|
||||
|
||||
self.assertRaises(InvalidToken, self.updater._bootstrap,
|
||||
retries, False, 'path', None)
|
||||
self.assertRaises(InvalidToken, self.updater._bootstrap, retries,
|
||||
False, 'path', None)
|
||||
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
||||
|
||||
def test_bootstrap_retries_fail(self):
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram User"""
|
||||
|
||||
import unittest
|
||||
|
@ -68,8 +67,8 @@ class UserTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(user.last_name, self.last_name)
|
||||
self.assertEqual(user.type, self.type)
|
||||
|
||||
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
|
||||
|
||||
self.assertEqual(user.name, '%s %s' %
|
||||
(self.first_name, self.last_name))
|
||||
|
||||
def test_user_de_json_without_username_and_lastname(self):
|
||||
json_dict = self.json_dict
|
||||
|
@ -99,5 +98,6 @@ class UserTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(user['username'], self.username)
|
||||
self.assertEqual(user['type'], self.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in a new issue