diff --git a/tests/base.py b/tests/base.py index 537a2d16f..6ec4c077c 100644 --- a/tests/base.py +++ b/tests/base.py @@ -19,11 +19,10 @@ """This module contains a object that represents a Base class for tests""" -import os -import sys import signal -import traceback +import sys +import os from nose.tools import make_decorator sys.path.append('.') @@ -38,7 +37,8 @@ class BaseTest(object): def __init__(self, *args, **kwargs): super(BaseTest, self).__init__(*args, **kwargs) - bot = telegram.Bot(os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0')) + bot = telegram.Bot(os.environ.get('TOKEN', + '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0')) chat_id = os.environ.get('CHAT_ID', '12173560') self._bot = bot @@ -62,7 +62,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_audio.py b/tests/test_audio.py index da7ebeb6f..f1603853e 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -19,9 +19,10 @@ """This module contains a object that represents Tests for Telegram Audio""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -195,7 +196,7 @@ class AudioTest(BaseTest, unittest.TestCase): def test_error_send_audio_empty_file(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['audio'] = open(os.devnull, 'rb') self.assertRaises(telegram.TelegramError, @@ -207,7 +208,7 @@ class AudioTest(BaseTest, unittest.TestCase): def test_error_send_audio_empty_file_id(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['audio'] = '' self.assertRaises(telegram.TelegramError, @@ -219,12 +220,13 @@ class AudioTest(BaseTest, unittest.TestCase): def test_error_audio_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) - del(json_dict['duration']) + del (json_dict['file_id']) + del (json_dict['duration']) self.assertRaises(TypeError, lambda: self._bot.sendAudio(chat_id=self._chat_id, **json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_bot.py b/tests/test_bot.py index 20ef84204..222368130 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -20,10 +20,10 @@ """This module contains a object that represents Tests for Telegram Bot""" -import io -import os -from datetime import datetime import sys +from datetime import datetime + +import io from flaky import flaky if sys.version_info[0:2] == (2, 6): @@ -59,7 +59,8 @@ class BotTest(BaseTest, unittest.TestCase): 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) @@ -70,7 +71,8 @@ class BotTest(BaseTest, unittest.TestCase): 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 +99,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 +111,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 +124,20 @@ 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 +145,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 +155,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) @@ -179,7 +188,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 +201,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_botan.py b/tests/test_botan.py index 7120c9097..6d5f2a0ea 100644 --- a/tests/test_botan.py +++ b/tests/test_botan.py @@ -2,9 +2,10 @@ """This module contains a object that represents Tests for Botan analytics integration""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -56,5 +57,6 @@ class BotanTest(BaseTest, unittest.TestCase): result = botan.track(message, 'named event') self.assertFalse(result) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_chat.py b/tests/test_chat.py index b5dd626b4..1d6eb1493 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 @@ -19,9 +19,9 @@ """This module contains a object that represents Tests for Telegram Chat""" -import os -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -67,5 +67,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_choseninlineresult.py b/tests/test_choseninlineresult.py index 872037aae..6ebc40086 100644 --- a/tests/test_choseninlineresult.py +++ b/tests/test_choseninlineresult.py @@ -37,7 +37,6 @@ class ChosenInlineResultTest(BaseTest, unittest.TestCase): """This object represents Tests for Telegram ChosenInlineResult.""" def setUp(self): - user = telegram.User(1, 'First name') self.result_id = 'result id' diff --git a/tests/test_contact.py b/tests/test_contact.py index 38e6cdca7..61853a9de 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 @@ -19,9 +19,9 @@ """This module contains a object that represents Tests for Telegram Contact""" -import os -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -66,5 +66,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_document.py b/tests/test_document.py index a7f9e8dad..61bebf4d8 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -19,9 +19,10 @@ """This module contains a object that represents Tests for Telegram Document""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -141,7 +142,7 @@ class DocumentTest(BaseTest, unittest.TestCase): def test_error_send_document_empty_file(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['document'] = open(os.devnull, 'rb') self.assertRaises(telegram.TelegramError, @@ -153,7 +154,7 @@ class DocumentTest(BaseTest, unittest.TestCase): def test_error_send_document_empty_file_id(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['document'] = '' self.assertRaises(telegram.TelegramError, @@ -165,11 +166,12 @@ class DocumentTest(BaseTest, unittest.TestCase): def test_error_document_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) self.assertRaises(TypeError, lambda: self._bot.sendDocument(chat_id=self._chat_id, **json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_emoji.py b/tests/test_emoji.py index d15bd2747..69700f299 100644 --- a/tests/test_emoji.py +++ b/tests/test_emoji.py @@ -19,12 +19,11 @@ """This module contains a object that represents Tests for Telegram Emoji""" -import os -import unittest import sys +import unittest + sys.path.append('.') -import telegram from telegram.emoji import Emoji from tests.base import BaseTest diff --git a/tests/test_file.py b/tests/test_file.py index 3347c99ad..aa54eaf72 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -19,9 +19,11 @@ """This module contains a object that represents Tests for Telegram File""" -import os -import unittest import sys +import unittest + +import os + sys.path.append('.') import telegram @@ -38,7 +40,6 @@ class FileTest(BaseTest, unittest.TestCase): self.video_file_id = 'BAADAQADXwADHyP1BwJFTcmY2RYCAg' self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg' - self.json_dict = { 'file_id': self.audio_file_id, 'file_path': 'https://api.telegram.org/file/bot133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0/document/file_3', @@ -123,8 +124,8 @@ class FileTest(BaseTest, unittest.TestCase): def test_error_get_empty_file_id(self): json_dict = self.json_dict json_dict['file_id'] = '' - del(json_dict['file_path']) - del(json_dict['file_size']) + del (json_dict['file_path']) + del (json_dict['file_size']) self.assertRaises(telegram.TelegramError, lambda: self._bot.getFile(**json_dict)) @@ -132,12 +133,13 @@ class FileTest(BaseTest, unittest.TestCase): def test_error_file_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) - del(json_dict['file_path']) - del(json_dict['file_size']) + del (json_dict['file_id']) + del (json_dict['file_path']) + del (json_dict['file_size']) self.assertRaises(TypeError, lambda: self._bot.getFile(**json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_forcereply.py b/tests/test_forcereply.py index dddefb756..b1ff08421 100644 --- a/tests/test_forcereply.py +++ b/tests/test_forcereply.py @@ -20,8 +20,9 @@ """This module contains a object that represents Tests for Telegram ForceReply""" -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -39,31 +40,34 @@ class ForceReplyTest(BaseTest, unittest.TestCase): 'force_reply': self.force_reply, 'selective': self.selective, } - + def test_send_message_with_force_reply(self): message = self._bot.sendMessage(self._chat_id, 'Моё судно на воздушной подушке полно угрей', - reply_markup=telegram.ForceReply.de_json(self.json_dict)) - + reply_markup=telegram.ForceReply.de_json( + self.json_dict)) + self.assertTrue(self.is_json(message.to_json())) - self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей') + self.assertEqual(message.text, + u'Моё судно на воздушной подушке полно угрей') def test_force_reply_de_json(self): force_reply = telegram.ForceReply.de_json(self.json_dict) self.assertEqual(force_reply.force_reply, self.force_reply) self.assertEqual(force_reply.selective, self.selective) - + def test_force_reply_to_json(self): force_reply = telegram.ForceReply.de_json(self.json_dict) self.assertTrue(self.is_json(force_reply.to_json())) - + def test_force_reply_to_dict(self): force_reply = telegram.ForceReply.de_json(self.json_dict) self.assertEqual(force_reply['force_reply'], self.force_reply) self.assertEqual(force_reply['selective'], self.selective) - + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_inlinequery.py b/tests/test_inlinequery.py index df08998f0..a8152625b 100644 --- a/tests/test_inlinequery.py +++ b/tests/test_inlinequery.py @@ -37,7 +37,6 @@ class InlineQueryTest(BaseTest, unittest.TestCase): """This object represents Tests for Telegram InlineQuery.""" def setUp(self): - user = telegram.User(1, 'First name') self.id = 'id' diff --git a/tests/test_inlinequeryresultcacheddocument.py b/tests/test_inlinequeryresultcacheddocument.py index eeb7aaa5c..2172c9f53 100644 --- a/tests/test_inlinequeryresultcacheddocument.py +++ b/tests/test_inlinequeryresultcacheddocument.py @@ -59,7 +59,6 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase): 'reply_markup': self.reply_markup.to_dict(), } - def test_document_de_json(self): document = telegram.InlineQueryResultCachedDocument.de_json( self.json_dict) diff --git a/tests/test_inlinequeryresultdocument.py b/tests/test_inlinequeryresultdocument.py index 2118010fb..772b77d3b 100644 --- a/tests/test_inlinequeryresultdocument.py +++ b/tests/test_inlinequeryresultdocument.py @@ -66,7 +66,6 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase): 'reply_markup': self.reply_markup.to_dict(), } - def test_document_de_json(self): document = telegram.InlineQueryResultDocument.de_json(self.json_dict) diff --git a/tests/test_inlinequeryresultvenue.py b/tests/test_inlinequeryresultvenue.py index 6e9aa18db..4ceed0ca0 100644 --- a/tests/test_inlinequeryresultvenue.py +++ b/tests/test_inlinequeryresultvenue.py @@ -42,7 +42,7 @@ class InlineQueryResultVenueTest(BaseTest, unittest.TestCase): self.latitude = 'latitude' self.longitude = 'longitude' self.title = 'title' - self._address = 'address' + self._address = 'address' # nose binds self.address for testing self.foursquare_id = 'foursquare id' self.thumb_url = 'thumb url' self.thumb_width = 10 diff --git a/tests/test_jobqueue.py b/tests/test_jobqueue.py index 84bcc9573..e8bf7aab5 100644 --- a/tests/test_jobqueue.py +++ b/tests/test_jobqueue.py @@ -46,7 +46,8 @@ root.setLevel(logging.INFO) ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.WARN) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +formatter = logging.Formatter( + '%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) root.addHandler(ch) @@ -111,5 +112,6 @@ class JobQueueTest(BaseTest, unittest.TestCase): sleep(2) self.assertEqual(1, self.result) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_location.py b/tests/test_location.py index b219ed337..b192fe1a0 100644 --- a/tests/test_location.py +++ b/tests/test_location.py @@ -19,9 +19,9 @@ """This module contains a object that represents Tests for Telegram Location""" -import os -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -90,12 +90,13 @@ class LocationTest(BaseTest, unittest.TestCase): def test_error_location_without_required_args(self): json_dict = self.json_dict - del(json_dict['latitude']) - del(json_dict['longitude']) + del (json_dict['latitude']) + del (json_dict['longitude']) self.assertRaises(TypeError, lambda: self._bot.sendLocation(chat_id=self._chat_id, **json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_parsemode.py b/tests/test_parsemode.py index b27117049..b426e4a7e 100644 --- a/tests/test_parsemode.py +++ b/tests/test_parsemode.py @@ -20,13 +20,15 @@ """This module contains a object that represents Tests for Telegram ParseMode""" -import unittest import sys +import unittest + sys.path.append('.') import telegram from tests.base import BaseTest + class ParseMode(BaseTest, unittest.TestCase): """This object represents Tests for Telegram ParseMode.""" @@ -34,22 +36,23 @@ class ParseMode(BaseTest, unittest.TestCase): self.markdown_text = "*bold* _italic_ [link](http://google.com)." self.html_text = 'bold italic link.' self.formatted_text_formatted = u'bold italic link.' - + def test_send_message_with_parse_mode_markdown(self): message = self._bot.sendMessage(chat_id=self._chat_id, text=self.markdown_text, parse_mode=telegram.ParseMode.MARKDOWN) - + self.assertTrue(self.is_json(message.to_json())) self.assertEqual(message.text, self.formatted_text_formatted) - + def test_send_message_with_parse_mode_html(self): message = self._bot.sendMessage(chat_id=self._chat_id, text=self.html_text, parse_mode=telegram.ParseMode.HTML) - + self.assertTrue(self.is_json(message.to_json())) self.assertEqual(message.text, self.formatted_text_formatted) - + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_photo.py b/tests/test_photo.py index 13d0d0e55..4c4d9a16c 100644 --- a/tests/test_photo.py +++ b/tests/test_photo.py @@ -19,9 +19,10 @@ """This module contains a object that represents Tests for Telegram Photo""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -171,7 +172,7 @@ class PhotoTest(BaseTest, unittest.TestCase): def test_error_send_photo_empty_file(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['photo'] = open(os.devnull, 'rb') self.assertRaises(telegram.TelegramError, @@ -183,7 +184,7 @@ class PhotoTest(BaseTest, unittest.TestCase): def test_error_send_photo_empty_file_id(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['photo'] = '' self.assertRaises(telegram.TelegramError, @@ -195,13 +196,14 @@ class PhotoTest(BaseTest, unittest.TestCase): def test_error_photo_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) - del(json_dict['width']) - del(json_dict['height']) + del (json_dict['file_id']) + del (json_dict['width']) + del (json_dict['height']) self.assertRaises(TypeError, lambda: self._bot.sendPhoto(chat_id=self._chat_id, **json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_replykeyboardhide.py b/tests/test_replykeyboardhide.py index 1fb1e4042..1ebf8aade 100644 --- a/tests/test_replykeyboardhide.py +++ b/tests/test_replykeyboardhide.py @@ -20,8 +20,9 @@ """This module contains a object that represents Tests for Telegram ReplyKeyboardHide""" -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -39,31 +40,38 @@ class ReplyKeyboardHideTest(BaseTest, unittest.TestCase): 'hide_keyboard': self.hide_keyboard, 'selective': self.selective, } - + def test_send_message_with_reply_keyboard_hide(self): message = self._bot.sendMessage(self._chat_id, 'Моё судно на воздушной подушке полно угрей', - reply_markup=telegram.ReplyKeyboardHide.de_json(self.json_dict)) - + reply_markup=telegram.ReplyKeyboardHide.de_json( + self.json_dict)) + self.assertTrue(self.is_json(message.to_json())) - self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей') + self.assertEqual(message.text, + u'Моё судно на воздушной подушке полно угрей') def test_reply_keyboard_hide_de_json(self): - reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict) + reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json( + self.json_dict) self.assertEqual(reply_keyboard_hide.hide_keyboard, self.hide_keyboard) self.assertEqual(reply_keyboard_hide.selective, self.selective) - + def test_reply_keyboard_hide_to_json(self): - reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict) + reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json( + self.json_dict) self.assertTrue(self.is_json(reply_keyboard_hide.to_json())) - - def test_reply_keyboard_hide_to_dict(self): - reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict) - self.assertEqual(reply_keyboard_hide['hide_keyboard'], self.hide_keyboard) + def test_reply_keyboard_hide_to_dict(self): + reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json( + self.json_dict) + + self.assertEqual(reply_keyboard_hide['hide_keyboard'], + self.hide_keyboard) self.assertEqual(reply_keyboard_hide['selective'], self.selective) - + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_replykeyboardmarkup.py b/tests/test_replykeyboardmarkup.py index d4102d6dd..90304706a 100644 --- a/tests/test_replykeyboardmarkup.py +++ b/tests/test_replykeyboardmarkup.py @@ -20,8 +20,9 @@ """This module contains a object that represents Tests for Telegram ReplyKeyboardMarkup""" -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -49,35 +50,45 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase): def test_send_message_with_reply_keyboard_markup(self): message = self._bot.sendMessage(self._chat_id, 'Моё судно на воздушной подушке полно угрей', - reply_markup=telegram.ReplyKeyboardMarkup.de_json(self.json_dict)) + reply_markup=telegram.ReplyKeyboardMarkup.de_json( + self.json_dict)) self.assertTrue(self.is_json(message.to_json())) - self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей') + self.assertEqual(message.text, + u'Моё судно на воздушной подушке полно угрей') def test_reply_keyboard_markup_de_json(self): - reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict) + reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json( + self.json_dict) self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list)) self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0], - telegram.KeyboardButton)) - self.assertEqual(reply_keyboard_markup.resize_keyboard, self.resize_keyboard) - self.assertEqual(reply_keyboard_markup.one_time_keyboard, self.one_time_keyboard) + telegram.KeyboardButton)) + self.assertEqual(reply_keyboard_markup.resize_keyboard, + self.resize_keyboard) + self.assertEqual(reply_keyboard_markup.one_time_keyboard, + self.one_time_keyboard) self.assertEqual(reply_keyboard_markup.selective, self.selective) def test_reply_keyboard_markup_to_json(self): - reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict) + reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json( + self.json_dict) self.assertTrue(self.is_json(reply_keyboard_markup.to_json())) def test_reply_keyboard_markup_to_dict(self): - reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict) + reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json( + self.json_dict) self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list)) self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0], - telegram.KeyboardButton)) - self.assertEqual(reply_keyboard_markup['resize_keyboard'], self.resize_keyboard) - self.assertEqual(reply_keyboard_markup['one_time_keyboard'], self.one_time_keyboard) + telegram.KeyboardButton)) + self.assertEqual(reply_keyboard_markup['resize_keyboard'], + self.resize_keyboard) + self.assertEqual(reply_keyboard_markup['one_time_keyboard'], + self.one_time_keyboard) self.assertEqual(reply_keyboard_markup['selective'], self.selective) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_sticker.py b/tests/test_sticker.py index 6f766df3e..9172ec66c 100644 --- a/tests/test_sticker.py +++ b/tests/test_sticker.py @@ -19,9 +19,10 @@ """This module contains a object that represents Tests for Telegram Sticker""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -60,7 +61,7 @@ class StickerTest(BaseTest, unittest.TestCase): @timeout(10) def test_send_sticker_resend(self): message = self._bot.sendSticker(chat_id=self._chat_id, - sticker=self.sticker_file_id) + sticker=self.sticker_file_id) sticker = message.sticker @@ -98,7 +99,7 @@ class StickerTest(BaseTest, unittest.TestCase): def test_error_send_sticker_empty_file(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['sticker'] = open(os.devnull, 'rb') self.assertRaises(telegram.TelegramError, @@ -110,23 +111,24 @@ class StickerTest(BaseTest, unittest.TestCase): def test_error_send_sticker_empty_file_id(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['sticker'] = '' self.assertRaises(telegram.TelegramError, lambda: self._bot.sendSticker(chat_id=self._chat_id, - **json_dict)) + **json_dict)) @flaky(3, 1) @timeout(10) def test_error_sticker_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) self.assertRaises(TypeError, lambda: self._bot.sendSticker(chat_id=self._chat_id, - **json_dict)) + **json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_update.py b/tests/test_update.py index 2533985dc..ac9d628df 100644 --- a/tests/test_update.py +++ b/tests/test_update.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 @@ -19,9 +19,9 @@ """This module contains a object that represents Tests for Telegram Update""" -import os -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -69,5 +69,6 @@ class UpdateTest(BaseTest, unittest.TestCase): self.assertEqual(update['update_id'], self.update_id) self.assertTrue(isinstance(update['message'], telegram.Message)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_updater.py b/tests/test_updater.py index b981aa52f..1f27b058b 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -23,14 +23,15 @@ This module contains a object that represents Tests for Updater, Dispatcher, WebhookServer and WebhookHandler """ import logging -import sys -import re -import os import signal -from random import randrange -from time import sleep +import sys from datetime import datetime +from time import sleep + +import os +import re from future.builtins import bytes +from random import randrange if sys.version_info[0:2] == (2, 6): import unittest2 as unittest @@ -570,7 +571,6 @@ class UpdaterTest(BaseTest, unittest.TestCase): req = Request(url, data=payload, headers=headers) - if get_method is not None: req.get_method = get_method @@ -602,7 +602,6 @@ class UpdaterTest(BaseTest, unittest.TestCase): class MockBot(object): - def __init__(self, text, messages=1, raise_error=False, bootstrap_retries=None, bootstrap_err=TelegramError('test')): self.text = text @@ -646,5 +645,6 @@ class MockBot(object): else: return [] + if __name__ == '__main__': unittest.main() diff --git a/tests/test_user.py b/tests/test_user.py index bbafe39a9..40bd9c160 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 @@ -19,9 +19,9 @@ """This module contains a object that represents Tests for Telegram User""" -import os -import unittest import sys +import unittest + sys.path.append('.') import telegram @@ -60,7 +60,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) @@ -69,14 +69,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) @@ -100,5 +100,6 @@ class UserTest(BaseTest, unittest.TestCase): self.assertEqual(user['username'], self.username) self.assertEqual(user['type'], self.type) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_video.py b/tests/test_video.py index fc9dd92be..6fcffcdbb 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -19,9 +19,10 @@ """This module contains a object that represents Tests for Telegram Video""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -217,7 +218,7 @@ class VideoTest(BaseTest, unittest.TestCase): def test_error_send_video_empty_file(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['video'] = open(os.devnull, 'rb') self.assertRaises(telegram.TelegramError, @@ -230,7 +231,7 @@ class VideoTest(BaseTest, unittest.TestCase): def test_error_send_video_empty_file_id(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['video'] = '' self.assertRaises(telegram.TelegramError, @@ -243,13 +244,14 @@ class VideoTest(BaseTest, unittest.TestCase): def test_error_video_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) - del(json_dict['duration']) + del (json_dict['file_id']) + del (json_dict['duration']) self.assertRaises(TypeError, lambda: self._bot.sendVideo(chat_id=self._chat_id, timeout=10, **json_dict)) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_voice.py b/tests/test_voice.py index 04617ce2b..935a57514 100644 --- a/tests/test_voice.py +++ b/tests/test_voice.py @@ -19,9 +19,10 @@ """This module contains a object that represents Tests for Telegram Voice""" -import os -import unittest import sys +import unittest + +import os from flaky import flaky sys.path.append('.') @@ -165,7 +166,7 @@ class VoiceTest(BaseTest, unittest.TestCase): def test_error_send_voice_empty_file(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['voice'] = open(os.devnull, 'rb') self.assertRaises(telegram.TelegramError, @@ -177,7 +178,7 @@ class VoiceTest(BaseTest, unittest.TestCase): def test_error_send_voice_empty_file_id(self): json_dict = self.json_dict - del(json_dict['file_id']) + del (json_dict['file_id']) json_dict['voice'] = '' self.assertRaises(telegram.TelegramError, @@ -189,12 +190,13 @@ class VoiceTest(BaseTest, unittest.TestCase): def test_error_voice_without_required_args(self): json_dict = self.json_dict - del(json_dict['file_id']) - del(json_dict['duration']) + del (json_dict['file_id']) + del (json_dict['duration']) self.assertRaises(TypeError, lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict)) + if __name__ == '__main__': unittest.main()