From 8ad1f330ead953975634ae04903f04c7b3ae8cd1 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Sat, 14 May 2016 21:39:11 -0300 Subject: [PATCH] First run of yapf for tests/* #259 --- requirements-dev.txt | 3 +- tests/base.py | 2 -- tests/test_bot.py | 71 +++++++++++++++++++++++++----------------- tests/test_chat.py | 4 +-- tests/test_contact.py | 4 +-- tests/test_emoji.py | 1 - tests/test_location.py | 4 +-- tests/test_updater.py | 8 ++--- tests/test_user.py | 14 ++++----- 9 files changed, 60 insertions(+), 51 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 3cd235bb0..720498d84 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,4 +3,5 @@ nose pep257 pylint unittest2 -flaky \ No newline at end of file +flaky +yapf diff --git a/tests/base.py b/tests/base.py index 7ee934209..8574c1764 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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 diff --git a/tests/test_bot.py b/tests/test_bot.py index 08fcd4ddc..ca2908523 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -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') diff --git a/tests/test_chat.py b/tests/test_chat.py index 22d84cf49..ce067f321 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -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() diff --git a/tests/test_contact.py b/tests/test_contact.py index c34cbcbb9..1df539fe6 100644 --- a/tests/test_contact.py +++ b/tests/test_contact.py @@ -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() diff --git a/tests/test_emoji.py b/tests/test_emoji.py index 4df2b5999..2f57aef16 100644 --- a/tests/test_emoji.py +++ b/tests/test_emoji.py @@ -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 diff --git a/tests/test_location.py b/tests/test_location.py index 4c224e4d1..c824a8ff5 100644 --- a/tests/test_location.py +++ b/tests/test_location.py @@ -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 diff --git a/tests/test_updater.py b/tests/test_updater.py index 1f81d551a..5d264709e 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -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): diff --git a/tests/test_user.py b/tests/test_user.py index 33ae93092..87d09eee3 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -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()