upgrade yapf to ver 0.12.2

This commit is contained in:
Noam Meltzer 2016-10-12 23:56:57 +03:00
parent d07a1c3f67
commit 5b8efe0c14
37 changed files with 153 additions and 132 deletions

View file

@ -682,11 +682,13 @@ class Bot(TelegramObject):
url = '{0}/sendVenue'.format(self.base_url)
data = {'chat_id': chat_id,
'latitude': latitude,
'longitude': longitude,
'address': address,
'title': title}
data = {
'chat_id': chat_id,
'latitude': latitude,
'longitude': longitude,
'address': address,
'title': title
}
if foursquare_id:
data['foursquare_id'] = foursquare_id

View file

@ -140,5 +140,7 @@ class Game(TelegramObject):
if types is None:
types = MessageEntity.ALL_TYPES
return {entity: self.parse_text_entity(entity)
for entity in self.text_entities if entity.type in types}
return {
entity: self.parse_text_entity(entity)
for entity in self.text_entities if entity.type in types
}

View file

@ -52,8 +52,10 @@ class InlineKeyboardMarkup(ReplyMarkup):
if not data:
return None
data['inline_keyboard'] = [InlineKeyboardButton.de_list(inline_keyboard, bot)
for inline_keyboard in data['inline_keyboard']]
data['inline_keyboard'] = [
InlineKeyboardButton.de_list(inline_keyboard, bot)
for inline_keyboard in data['inline_keyboard']
]
return InlineKeyboardMarkup(**data)

View file

@ -465,5 +465,7 @@ class Message(TelegramObject):
if types is None:
types = MessageEntity.ALL_TYPES
return {entity: self.parse_entity(entity)
for entity in self.entities if entity.type in types}
return {
entity: self.parse_entity(entity)
for entity in self.entities if entity.type in types
}

View file

@ -80,5 +80,6 @@ class MessageEntity(TelegramObject):
PRE = 'pre'
TEXT_LINK = 'text_link'
TEXT_MENTION = 'text_mention'
ALL_TYPES = [MENTION, HASHTAG, BOT_COMMAND, URL, EMAIL, BOLD, ITALIC, CODE, PRE, TEXT_LINK,
TEXT_MENTION]
ALL_TYPES = [
MENTION, HASHTAG, BOT_COMMAND, URL, EMAIL, BOLD, ITALIC, CODE, PRE, TEXT_LINK, TEXT_MENTION
]

View file

@ -38,10 +38,12 @@ class ChatTest(BaseTest, unittest.TestCase):
self.type = 'group'
self.all_members_are_admins = False
self.json_dict = {'id': self.id,
'title': self.title,
'type': self.type,
'all_members_are_admins': self.all_members_are_admins}
self.json_dict = {
'id': self.id,
'title': self.title,
'type': self.type,
'all_members_are_admins': self.all_members_are_admins
}
def test_group_chat_de_json_empty_json(self):
group_chat = telegram.Chat.de_json({}, self._bot)

View file

@ -66,14 +66,17 @@ class ConversationHandlerTest(BaseTest, unittest.TestCase):
def setUp(self):
self.current_state = dict()
self.entry_points = [CommandHandler('start', self.start)]
self.states = {self.THIRSTY: [CommandHandler('brew', self.brew),
CommandHandler('wait', self.start)],
self.BREWING: [CommandHandler('pourCoffee', self.drink)],
self.DRINKING: [CommandHandler('startCoding', self.code),
CommandHandler('drinkMore', self.drink)],
self.CODING: [CommandHandler('keepCoding', self.code),
CommandHandler('gettingThirsty', self.start),
CommandHandler('drinkMore', self.drink)],}
self.states = {
self.THIRSTY: [CommandHandler('brew', self.brew), CommandHandler('wait', self.start)],
self.BREWING: [CommandHandler('pourCoffee', self.drink)],
self.DRINKING:
[CommandHandler('startCoding', self.code), CommandHandler('drinkMore', self.drink)],
self.CODING: [
CommandHandler('keepCoding', self.code),
CommandHandler('gettingThirsty', self.start),
CommandHandler('drinkMore', self.drink)
],
}
self.fallbacks = [CommandHandler('eat', self.start)]
def _setup_updater(self, *args, **kwargs):

View file

@ -37,10 +37,12 @@ class DocumentTest(BaseTest, unittest.TestCase):
self.document_file = open('tests/data/telegram.png', 'rb')
self.document_file_id = 'BQADAQADpAADHyP1B04ipZxJTe2BAg'
self.document_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.gif'
self.thumb = {'width': 90,
'height': 90,
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
'file_size': 2364}
self.thumb = {
'width': 90,
'height': 90,
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
'file_size': 2364
}
self.file_name = 'telegram.png'
self.mime_type = 'image/png'
self.file_size = 12948

View file

@ -35,8 +35,10 @@ class ForceReplyTest(BaseTest, unittest.TestCase):
self.force_reply = True
self.selective = True
self.json_dict = {'force_reply': self.force_reply,
'selective': self.selective,}
self.json_dict = {
'force_reply': self.force_reply,
'selective': self.selective,
}
def test_send_message_with_force_reply(self):
message = self._bot.sendMessage(

View file

@ -96,8 +96,9 @@ class GameTest(BaseTest, unittest.TestCase):
self.title, self.description, self.photo, text=text, text_entities=[entity_2, entity])
self.assertDictEqual(
game.parse_text_entities(telegram.MessageEntity.URL), {entity: 'http://google.com'})
self.assertDictEqual(game.parse_text_entities(), {entity: 'http://google.com',
entity_2: 'h'})
self.assertDictEqual(game.parse_text_entities(),
{entity: 'http://google.com',
entity_2: 'h'})
class AnimationTest(BaseTest, unittest.TestCase):

View file

@ -32,13 +32,15 @@ class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram KeyboardButton."""
def setUp(self):
self.inline_keyboard = [[telegram.InlineKeyboardButton(
text='button1', callback_data='data1'), telegram.InlineKeyboardButton(
text='button2', callback_data='data2')]]
self.inline_keyboard = [[
telegram.InlineKeyboardButton(
text='button1', callback_data='data1'), telegram.InlineKeyboardButton(
text='button2', callback_data='data2')
]]
self.json_dict = {
'inline_keyboard': [[self.inline_keyboard[0][0].to_dict(),
self.inline_keyboard[0][1].to_dict()]],
'inline_keyboard':
[[self.inline_keyboard[0][0].to_dict(), self.inline_keyboard[0][1].to_dict()]],
}
def test_send_message_with_inline_keyboard_markup(self):

View file

@ -36,9 +36,8 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
self.type = 'article'
self.title = 'title'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.url = 'url'
self.hide_url = True
self.description = 'description'

View file

@ -40,9 +40,8 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
self.audio_duration = 'audio_duration'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -38,9 +38,8 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
self.audio_file_id = 'audio file id'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -40,9 +40,8 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
self.caption = 'caption'
self.description = 'description'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -38,9 +38,8 @@ class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -39,9 +39,8 @@ class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -40,9 +40,8 @@ class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
self.description = 'description'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -37,9 +37,8 @@ class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
self.type = 'sticker'
self.sticker_file_id = 'sticker file id'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -40,9 +40,8 @@ class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
self.caption = 'caption'
self.description = 'description'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -39,9 +39,8 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -41,9 +41,8 @@ class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
self.thumb_width = 10
self.thumb_height = 15
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -43,9 +43,8 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
self.thumb_width = 10
self.thumb_height = 15
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -41,9 +41,8 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -41,9 +41,8 @@ class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
self.thumb_width = 10
self.thumb_height = 15
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -41,9 +41,8 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -42,9 +42,8 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
self.description = 'description'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -43,9 +43,8 @@ class InlineQueryResultVenueTest(BaseTest, unittest.TestCase):
self.thumb_width = 10
self.thumb_height = 15
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -44,9 +44,8 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
self.caption = 'caption'
self.description = 'description'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -39,9 +39,8 @@ class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
self.voice_duration = 'voice_duration'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -35,8 +35,10 @@ class InputLocationMessageContentTest(BaseTest, unittest.TestCase):
self.latitude = 1.
self.longitude = 2.
self.json_dict = {'longitude': self.longitude,
'latitude': self.latitude,}
self.json_dict = {
'longitude': self.longitude,
'latitude': self.latitude,
}
def test_ilmc_de_json(self):
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict, self._bot)

View file

@ -55,8 +55,9 @@ class MessageTest(BaseTest, unittest.TestCase):
entities=[entity_2, entity])
self.assertDictEqual(
message.parse_entities(telegram.MessageEntity.URL), {entity: 'http://google.com'})
self.assertDictEqual(message.parse_entities(), {entity: 'http://google.com',
entity_2: 'h'})
self.assertDictEqual(message.parse_entities(),
{entity: 'http://google.com',
entity_2: 'h'})
@flaky(3, 1)
def test_reply_text(self):

View file

@ -35,8 +35,10 @@ class ReplyKeyboardHideTest(BaseTest, unittest.TestCase):
self.hide_keyboard = True
self.selective = True
self.json_dict = {'hide_keyboard': self.hide_keyboard,
'selective': self.selective,}
self.json_dict = {
'hide_keyboard': self.hide_keyboard,
'selective': self.selective,
}
def test_send_message_with_reply_keyboard_hide(self):
message = self._bot.sendMessage(

View file

@ -38,10 +38,12 @@ class StickerTest(BaseTest, unittest.TestCase):
self.sticker_file_id = 'BQADAQADHAADyIsGAAFZfq1bphjqlgI'
self.width = 510
self.height = 512
self.thumb = {'width': 90,
'height': 90,
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
'file_size': 2364}
self.thumb = {
'width': 90,
'height': 90,
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
'file_size': 2364
}
self.emoji = telegram.Emoji.FLEXED_BICEPS
self.file_size = 39518

View file

@ -32,18 +32,24 @@ class UpdateTest(BaseTest, unittest.TestCase):
def setUp(self):
self.update_id = 868573637
self.message = {'message_id': 319,
'from': {'id': 12173560,
'first_name': "Leandro",
'last_name': "S.",
'username': "leandrotoledo"},
'chat': {'id': 12173560,
'type': 'private',
'first_name': "Leandro",
'last_name': "S.",
'username': "leandrotoledo"},
'date': 1441644592,
'text': "Update Test"}
self.message = {
'message_id': 319,
'from': {
'id': 12173560,
'first_name': "Leandro",
'last_name': "S.",
'username': "leandrotoledo"
},
'chat': {
'id': 12173560,
'type': 'private',
'first_name': "Leandro",
'last_name': "S.",
'username': "leandrotoledo"
},
'date': 1441644592,
'text': "Update Test"
}
self.json_dict = {'update_id': self.update_id, 'message': self.message}

View file

@ -496,8 +496,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
queue = self.updater.start_polling(0.01)
queue.put('This is a test message for regex group matching.')
sleep(.1)
self.assertEqual(self.received_message, (('This', 'regex group'),
{'testgroup': 'regex group'}))
self.assertEqual(self.received_message, (('This', 'regex group'), {
'testgroup': 'regex group'
}))
def test_regexGroupHandlerInlineQuery(self):
self._setup_updater('', messages=0)
@ -516,8 +517,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
0, None, 'This is a test message for regex group matching.', None)))
sleep(.1)
self.assertEqual(self.received_message, (('This', 'regex group'),
{'testgroup': 'regex group'}))
self.assertEqual(self.received_message, (('This', 'regex group'), {
'testgroup': 'regex group'
}))
def test_regexGroupHandlerCallbackQuery(self):
self._setup_updater('', messages=0)
@ -536,8 +538,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
0, None, None, data='This is a test message for regex group matching.')))
sleep(.1)
self.assertEqual(self.received_message, (('This', 'regex group'),
{'testgroup': 'regex group'}))
self.assertEqual(self.received_message, (('This', 'regex group'), {
'testgroup': 'regex group'
}))
def test_runAsyncWithAdditionalArgs(self):
self._setup_updater('Test6', messages=2)

View file

@ -40,15 +40,18 @@ class VideoTest(BaseTest, unittest.TestCase):
self.width = 360
self.height = 640
self.duration = 5
self.thumb = telegram.PhotoSize.de_json({'file_id': 'AAQBABOMsecvAAQqqoY1Pee_MqcyAAIC',
'file_size': 645,
'height': 90,
'width': 51}, self._bot)
self.thumb_from_url = telegram.PhotoSize.de_json({'file_id':
'AAQEABPZU2EZAAQ_tPcvcRTF4i1GAQABAg',
'file_size': 645,
'height': 90,
'width': 51}, self._bot)
self.thumb = telegram.PhotoSize.de_json({
'file_id': 'AAQBABOMsecvAAQqqoY1Pee_MqcyAAIC',
'file_size': 645,
'height': 90,
'width': 51
}, self._bot)
self.thumb_from_url = telegram.PhotoSize.de_json({
'file_id': 'AAQEABPZU2EZAAQ_tPcvcRTF4i1GAQABAg',
'file_size': 645,
'height': 90,
'width': 51
}, self._bot)
self.mime_type = 'video/mp4'
self.file_size = 326534