First run of yapf for tests/* #259

This commit is contained in:
Leandro Toledo 2016-05-14 21:39:11 -03:00
parent 56b1d4f5ce
commit 8ad1f330ea
9 changed files with 60 additions and 51 deletions

View file

@ -3,4 +3,5 @@ nose
pep257
pylint
unittest2
flaky
flaky
yapf

View file

@ -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

View file

@ -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,
text='Моё судно на воздушной подушке полно угрей')
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,
text='Моё судно на воздушной подушке полно угрей',
disable_notification=True)
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,9 +100,10 @@ class BotTest(BaseTest, unittest.TestCase):
@flaky(3, 1)
@timeout(10)
def testSendPhoto(self):
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
caption='testSendPhoto',
chat_id=self._chat_id)
message = self._bot.sendPhoto(
photo=open('tests/data/telegram.png', 'rb'),
caption='testSendPhoto',
chat_id=self._chat_id)
self.assertTrue(self.is_json(message.to_json()))
self.assertEqual(message.photo[0].file_size, 1451)
@ -108,10 +112,11 @@ class BotTest(BaseTest, unittest.TestCase):
@flaky(3, 1)
@timeout(10)
def testSilentSendPhoto(self):
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
caption='testSendPhoto',
chat_id=self._chat_id,
disable_notification=True)
message = self._bot.sendPhoto(
photo=open('tests/data/telegram.png', 'rb'),
caption='testSendPhoto',
chat_id=self._chat_id,
disable_notification=True)
self.assertTrue(self.is_json(message.to_json()))
self.assertEqual(message.photo[0].file_size, 1451)
@ -120,17 +125,21 @@ class BotTest(BaseTest, unittest.TestCase):
@flaky(3, 1)
@timeout(10)
def testResendPhoto(self):
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
chat_id=self._chat_id)
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',
chat_id=self._chat_id)
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()))
self.assertEqual(message.photo[0].file_size, 822)
@ -138,8 +147,9 @@ 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',
chat_id=self._chat_id)
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()))
self.assertEqual(message.photo[0].file_size, 684)
@ -147,8 +157,9 @@ 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',
chat_id=self._chat_id)
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()))
self.assertEqual(message.photo[0].file_size, 684)
@ -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')

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2016
@ -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()

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2016
@ -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()

View file

@ -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

View file

@ -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

View file

@ -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):

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2016
@ -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
@ -59,7 +58,7 @@ class UserTest(BaseTest, unittest.TestCase):
def test_user_de_json_without_username(self):
json_dict = self.json_dict
del(json_dict['username'])
del (json_dict['username'])
user = telegram.User.de_json(self.json_dict)
@ -68,14 +67,14 @@ 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
del(json_dict['username'])
del(json_dict['last_name'])
del (json_dict['username'])
del (json_dict['last_name'])
user = telegram.User.de_json(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()