2222import os
2323import unittest
2424import sys
25+ from flaky import flaky
26+
2527sys .path .append ('.' )
2628
2729import telegram
28- from tests .base import BaseTest
30+ from tests .base import BaseTest , timeout
2931
3032
3133class AudioTest (BaseTest , unittest .TestCase ):
@@ -50,10 +52,9 @@ def setUp(self):
5052 'file_size' : self .file_size
5153 }
5254
55+ @flaky (3 , 1 )
56+ @timeout (10 )
5357 def test_send_audio_required_args_only (self ):
54- """Test telegram.Bot sendAudio method"""
55- print ('Testing bot.sendAudio - With required arguments only' )
56-
5758 message = self ._bot .sendAudio (self ._chat_id ,
5859 self .audio_file )
5960
@@ -67,10 +68,9 @@ def test_send_audio_required_args_only(self):
6768 self .assertEqual (audio .mime_type , self .mime_type )
6869 self .assertEqual (audio .file_size , self .file_size )
6970
71+ @flaky (3 , 1 )
72+ @timeout (10 )
7073 def test_send_audio_all_args (self ):
71- """Test telegram.Bot sendAudio method"""
72- print ('Testing bot.sendAudio - With all arguments' )
73-
7474 message = self ._bot .sendAudio (self ._chat_id ,
7575 self .audio_file ,
7676 duration = self .duration ,
@@ -89,10 +89,9 @@ def test_send_audio_all_args(self):
8989 self .assertEqual (audio .mime_type , self .mime_type )
9090 self .assertEqual (audio .file_size , self .file_size )
9191
92+ @flaky (3 , 1 )
93+ @timeout (10 )
9294 def test_send_audio_mp3_file (self ):
93- """Test telegram.Bot sendAudio method"""
94- print ('Testing bot.sendAudio - MP3 File' )
95-
9695 message = self ._bot .sendAudio (chat_id = self ._chat_id ,
9796 audio = self .audio_file ,
9897 duration = self .duration ,
@@ -109,10 +108,9 @@ def test_send_audio_mp3_file(self):
109108 self .assertEqual (audio .mime_type , self .mime_type )
110109 self .assertEqual (audio .file_size , self .file_size )
111110
111+ @flaky (3 , 1 )
112+ @timeout (10 )
112113 def test_send_audio_mp3_file_custom_filename (self ):
113- """Test telegram.Bot sendAudio method"""
114- print ('Testing bot.sendAudio - MP3 File with custom filename' )
115-
116114 message = self ._bot .sendAudio (chat_id = self ._chat_id ,
117115 audio = self .audio_file ,
118116 duration = self .duration ,
@@ -130,10 +128,9 @@ def test_send_audio_mp3_file_custom_filename(self):
130128 self .assertEqual (audio .mime_type , self .mime_type )
131129 self .assertEqual (audio .file_size , self .file_size )
132130
131+ @flaky (3 , 1 )
132+ @timeout (10 )
133133 def test_send_audio_mp3_url_file (self ):
134- """Test telegram.Bot sendAudio method"""
135- print ('Testing bot.sendAudio - MP3 File by URL' )
136-
137134 message = self ._bot .sendAudio (chat_id = self ._chat_id ,
138135 audio = self .audio_file_url ,
139136 duration = self .duration ,
@@ -150,10 +147,9 @@ def test_send_audio_mp3_url_file(self):
150147 self .assertEqual (audio .mime_type , self .mime_type )
151148 self .assertEqual (audio .file_size , self .file_size )
152149
150+ @flaky (3 , 1 )
151+ @timeout (10 )
153152 def test_send_audio_resend (self ):
154- """Test telegram.Bot sendAudio method"""
155- print ('Testing bot.sendAudio - Resend by file_id' )
156-
157153 message = self ._bot .sendAudio (chat_id = self ._chat_id ,
158154 audio = self .audio_file_id ,
159155 duration = self .duration ,
@@ -169,9 +165,6 @@ def test_send_audio_resend(self):
169165 self .assertEqual (audio .mime_type , self .mime_type )
170166
171167 def test_audio_de_json (self ):
172- """Test Audio.de_json() method"""
173- print ('Testing Audio.de_json()' )
174-
175168 audio = telegram .Audio .de_json (self .json_dict )
176169
177170 self .assertEqual (audio .file_id , self .audio_file_id )
@@ -182,17 +175,11 @@ def test_audio_de_json(self):
182175 self .assertEqual (audio .file_size , self .file_size )
183176
184177 def test_audio_to_json (self ):
185- """Test Audio.to_json() method"""
186- print ('Testing Audio.to_json()' )
187-
188178 audio = telegram .Audio .de_json (self .json_dict )
189179
190180 self .assertTrue (self .is_json (audio .to_json ()))
191181
192182 def test_audio_to_dict (self ):
193- """Test Audio.to_dict() method"""
194- print ('Testing Audio.to_dict()' )
195-
196183 audio = telegram .Audio .de_json (self .json_dict )
197184
198185 self .assertTrue (self .is_dict (audio .to_dict ()))
@@ -203,9 +190,9 @@ def test_audio_to_dict(self):
203190 self .assertEqual (audio ['mime_type' ], self .mime_type )
204191 self .assertEqual (audio ['file_size' ], self .file_size )
205192
193+ @flaky (3 , 1 )
194+ @timeout (10 )
206195 def test_error_send_audio_empty_file (self ):
207- print ('Testing bot.sendAudio - Null file' )
208-
209196 json_dict = self .json_dict
210197
211198 del (json_dict ['file_id' ])
@@ -215,9 +202,9 @@ def test_error_send_audio_empty_file(self):
215202 lambda : self ._bot .sendAudio (chat_id = self ._chat_id ,
216203 ** json_dict ))
217204
205+ @flaky (3 , 1 )
206+ @timeout (10 )
218207 def test_error_send_audio_empty_file_id (self ):
219- print ('Testing bot.sendAudio - Empty file_id' )
220-
221208 json_dict = self .json_dict
222209
223210 del (json_dict ['file_id' ])
@@ -227,9 +214,9 @@ def test_error_send_audio_empty_file_id(self):
227214 lambda : self ._bot .sendAudio (chat_id = self ._chat_id ,
228215 ** json_dict ))
229216
217+ @flaky (3 , 1 )
218+ @timeout (10 )
230219 def test_error_audio_without_required_args (self ):
231- print ('Testing bot.sendAudio - Without required arguments' )
232-
233220 json_dict = self .json_dict
234221
235222 del (json_dict ['file_id' ])
0 commit comments