X Tutup
Skip to content

Commit ca1fff2

Browse files
committed
Some code reformat and minor fixes
1 parent 0d6b3a5 commit ca1fff2

27 files changed

+207
-152
lines changed

tests/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
"""This module contains a object that represents a Base class for tests"""
2121

22-
import os
23-
import sys
2422
import signal
25-
import traceback
23+
import sys
2624

25+
import os
2726
from nose.tools import make_decorator
2827

2928
sys.path.append('.')
@@ -38,7 +37,8 @@ class BaseTest(object):
3837
def __init__(self, *args, **kwargs):
3938
super(BaseTest, self).__init__(*args, **kwargs)
4039

41-
bot = telegram.Bot(os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
40+
bot = telegram.Bot(os.environ.get('TOKEN',
41+
'133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
4242
chat_id = os.environ.get('CHAT_ID', '12173560')
4343

4444
self._bot = bot
@@ -62,7 +62,6 @@ def is_dict(dictionary):
6262

6363

6464
class TestTimedOut(AssertionError):
65-
6665
def __init__(self, time_limit, frame):
6766
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
6867
self.time_limit = time_limit

tests/test_audio.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
"""This module contains a object that represents Tests for Telegram Audio"""
2121

22-
import os
23-
import unittest
2422
import sys
23+
import unittest
24+
25+
import os
2526
from flaky import flaky
2627

2728
sys.path.append('.')
@@ -195,7 +196,7 @@ def test_audio_to_dict(self):
195196
def test_error_send_audio_empty_file(self):
196197
json_dict = self.json_dict
197198

198-
del(json_dict['file_id'])
199+
del (json_dict['file_id'])
199200
json_dict['audio'] = open(os.devnull, 'rb')
200201

201202
self.assertRaises(telegram.TelegramError,
@@ -207,7 +208,7 @@ def test_error_send_audio_empty_file(self):
207208
def test_error_send_audio_empty_file_id(self):
208209
json_dict = self.json_dict
209210

210-
del(json_dict['file_id'])
211+
del (json_dict['file_id'])
211212
json_dict['audio'] = ''
212213

213214
self.assertRaises(telegram.TelegramError,
@@ -219,12 +220,13 @@ def test_error_send_audio_empty_file_id(self):
219220
def test_error_audio_without_required_args(self):
220221
json_dict = self.json_dict
221222

222-
del(json_dict['file_id'])
223-
del(json_dict['duration'])
223+
del (json_dict['file_id'])
224+
del (json_dict['duration'])
224225

225226
self.assertRaises(TypeError,
226227
lambda: self._bot.sendAudio(chat_id=self._chat_id,
227228
**json_dict))
228229

230+
229231
if __name__ == '__main__':
230232
unittest.main()

tests/test_bot.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
"""This module contains a object that represents Tests for Telegram Bot"""
2222

23-
import io
24-
import os
25-
from datetime import datetime
2623
import sys
24+
from datetime import datetime
25+
26+
import io
2727
from flaky import flaky
2828

2929
if sys.version_info[0:2] == (2, 6):
@@ -59,7 +59,8 @@ def testSendMessage(self):
5959
text='Моё судно на воздушной подушке полно угрей')
6060

6161
self.assertTrue(self.is_json(message.to_json()))
62-
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
62+
self.assertEqual(message.text,
63+
u'Моё судно на воздушной подушке полно угрей')
6364
self.assertTrue(isinstance(message.date, datetime))
6465

6566
@flaky(3, 1)
@@ -70,7 +71,8 @@ def testSilentSendMessage(self):
7071
disable_notification=True)
7172

7273
self.assertTrue(self.is_json(message.to_json()))
73-
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
74+
self.assertEqual(message.text,
75+
u'Моё судно на воздушной подушке полно угрей')
7476
self.assertTrue(isinstance(message.date, datetime))
7577

7678
@flaky(3, 1)
@@ -97,9 +99,10 @@ def testForwardMessage(self):
9799
@flaky(3, 1)
98100
@timeout(10)
99101
def testSendPhoto(self):
100-
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
101-
caption='testSendPhoto',
102-
chat_id=self._chat_id)
102+
message = self._bot.sendPhoto(
103+
photo=open('tests/data/telegram.png', 'rb'),
104+
caption='testSendPhoto',
105+
chat_id=self._chat_id)
103106

104107
self.assertTrue(self.is_json(message.to_json()))
105108
self.assertEqual(message.photo[0].file_size, 1451)
@@ -108,10 +111,11 @@ def testSendPhoto(self):
108111
@flaky(3, 1)
109112
@timeout(10)
110113
def testSilentSendPhoto(self):
111-
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
112-
caption='testSendPhoto',
113-
chat_id=self._chat_id,
114-
disable_notification=True)
114+
message = self._bot.sendPhoto(
115+
photo=open('tests/data/telegram.png', 'rb'),
116+
caption='testSendPhoto',
117+
chat_id=self._chat_id,
118+
disable_notification=True)
115119

116120
self.assertTrue(self.is_json(message.to_json()))
117121
self.assertEqual(message.photo[0].file_size, 1451)
@@ -120,35 +124,40 @@ def testSilentSendPhoto(self):
120124
@flaky(3, 1)
121125
@timeout(10)
122126
def testResendPhoto(self):
123-
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
124-
chat_id=self._chat_id)
127+
message = self._bot.sendPhoto(
128+
photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
129+
chat_id=self._chat_id)
125130

126131
self.assertTrue(self.is_json(message.to_json()))
127-
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
132+
self.assertEqual(message.photo[0].file_id,
133+
'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
128134

129135
@flaky(3, 1)
130136
@timeout(10)
131137
def testSendJPGURLPhoto(self):
132-
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
133-
chat_id=self._chat_id)
138+
message = self._bot.sendPhoto(
139+
photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
140+
chat_id=self._chat_id)
134141

135142
self.assertTrue(self.is_json(message.to_json()))
136143
self.assertEqual(message.photo[0].file_size, 822)
137144

138145
@flaky(3, 1)
139146
@timeout(10)
140147
def testSendPNGURLPhoto(self):
141-
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
142-
chat_id=self._chat_id)
148+
message = self._bot.sendPhoto(
149+
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
150+
chat_id=self._chat_id)
143151

144152
self.assertTrue(self.is_json(message.to_json()))
145153
self.assertEqual(message.photo[0].file_size, 684)
146154

147155
@flaky(3, 1)
148156
@timeout(10)
149157
def testSendGIFURLPhoto(self):
150-
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
151-
chat_id=self._chat_id)
158+
message = self._bot.sendPhoto(
159+
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
160+
chat_id=self._chat_id)
152161

153162
self.assertTrue(self.is_json(message.to_json()))
154163
self.assertEqual(message.photo[0].file_size, 684)
@@ -179,7 +188,8 @@ def testGetUserProfilePhotos(self):
179188
self.assertEqual(upf.photos[0][0].file_size, 12421)
180189

181190
def _test_invalid_token(self, token):
182-
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token', telegram.Bot, token)
191+
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token',
192+
telegram.Bot, token)
183193

184194
def testInvalidToken1(self):
185195
self._test_invalid_token('123')
@@ -191,12 +201,14 @@ def testInvalidToken3(self):
191201
self._test_invalid_token('12:')
192202

193203
def testUnauthToken(self):
194-
with self.assertRaisesRegexp(telegram.error.Unauthorized, 'Unauthorized'):
204+
with self.assertRaisesRegexp(telegram.error.Unauthorized,
205+
'Unauthorized'):
195206
bot = telegram.Bot('1234:abcd1234')
196207
bot.getMe()
197208

198209
def testInvalidSrvResp(self):
199-
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
210+
with self.assertRaisesRegexp(telegram.TelegramError,
211+
'Invalid server response'):
200212
# bypass the valid token check
201213
bot = telegram.Bot.__new__(telegram.Bot)
202214
bot.base_url = 'https://api.telegram.org/bot{0}'.format('12')

tests/test_botan.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
"""This module contains a object that represents Tests for Botan analytics integration"""
44

5-
import os
6-
import unittest
75
import sys
6+
import unittest
7+
8+
import os
89
from flaky import flaky
910

1011
sys.path.append('.')
@@ -56,5 +57,6 @@ def test_wrong_endpoint(self):
5657
result = botan.track(message, 'named event')
5758
self.assertFalse(result)
5859

60+
5961
if __name__ == '__main__':
6062
unittest.main()

tests/test_chat.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
# !/usr/bin/env python
22
#
33
# A library that provides a Python interface to the Telegram Bot API
44
# Copyright (C) 2015-2016
@@ -19,9 +19,9 @@
1919

2020
"""This module contains a object that represents Tests for Telegram Chat"""
2121

22-
import os
23-
import unittest
2422
import sys
23+
import unittest
24+
2525
sys.path.append('.')
2626

2727
import telegram
@@ -67,5 +67,6 @@ def test_group_chat_to_dict(self):
6767
self.assertEqual(group_chat['title'], self.title)
6868
self.assertEqual(group_chat['type'], self.type)
6969

70+
7071
if __name__ == '__main__':
7172
unittest.main()

tests/test_choseninlineresult.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class ChosenInlineResultTest(BaseTest, unittest.TestCase):
3737
"""This object represents Tests for Telegram ChosenInlineResult."""
3838

3939
def setUp(self):
40-
4140
user = telegram.User(1, 'First name')
4241

4342
self.result_id = 'result id'

tests/test_contact.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
# !/usr/bin/env python
22
#
33
# A library that provides a Python interface to the Telegram Bot API
44
# Copyright (C) 2015-2016
@@ -19,9 +19,9 @@
1919

2020
"""This module contains a object that represents Tests for Telegram Contact"""
2121

22-
import os
23-
import unittest
2422
import sys
23+
import unittest
24+
2525
sys.path.append('.')
2626

2727
import telegram
@@ -66,5 +66,6 @@ def test_contact_to_dict(self):
6666
self.assertEqual(contact['last_name'], self.last_name)
6767
self.assertEqual(contact['user_id'], self.user_id)
6868

69+
6970
if __name__ == '__main__':
7071
unittest.main()

tests/test_document.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
"""This module contains a object that represents Tests for Telegram Document"""
2121

22-
import os
23-
import unittest
2422
import sys
23+
import unittest
24+
25+
import os
2526
from flaky import flaky
2627

2728
sys.path.append('.')
@@ -141,7 +142,7 @@ def test_document_to_dict(self):
141142
def test_error_send_document_empty_file(self):
142143
json_dict = self.json_dict
143144

144-
del(json_dict['file_id'])
145+
del (json_dict['file_id'])
145146
json_dict['document'] = open(os.devnull, 'rb')
146147

147148
self.assertRaises(telegram.TelegramError,
@@ -153,7 +154,7 @@ def test_error_send_document_empty_file(self):
153154
def test_error_send_document_empty_file_id(self):
154155
json_dict = self.json_dict
155156

156-
del(json_dict['file_id'])
157+
del (json_dict['file_id'])
157158
json_dict['document'] = ''
158159

159160
self.assertRaises(telegram.TelegramError,
@@ -165,11 +166,12 @@ def test_error_send_document_empty_file_id(self):
165166
def test_error_document_without_required_args(self):
166167
json_dict = self.json_dict
167168

168-
del(json_dict['file_id'])
169+
del (json_dict['file_id'])
169170

170171
self.assertRaises(TypeError,
171172
lambda: self._bot.sendDocument(chat_id=self._chat_id,
172173
**json_dict))
173174

175+
174176
if __name__ == '__main__':
175177
unittest.main()

tests/test_emoji.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
"""This module contains a object that represents Tests for Telegram Emoji"""
2121

22-
import os
23-
import unittest
2422
import sys
23+
import unittest
24+
2525
sys.path.append('.')
2626

27-
import telegram
2827
from telegram.emoji import Emoji
2928
from tests.base import BaseTest
3029

0 commit comments

Comments
 (0)
X Tutup