Skip to content

Commit dd20237

Browse files
authored
Enable appveyor (python-telegram-bot#823)
* modify tests and appveyor.yml * modify test_meta * Add pytest-cov to requirements * appveyor.yaml adjustment * another try * oops * skipping jobqueue tests on appveyor appveyor is terrible at precise timings. * adding reasons to skips * modify test_official * coverage trouble * Make it look good * appveyor.yml * codecov flags * oops * update appveyor.yml * shorten decorators * removed redundant quotes
1 parent c5ab893 commit dd20237

File tree

8 files changed

+50
-16
lines changed

8 files changed

+50
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ script:
3636

3737
after_success:
3838
- coverage combine
39-
- codecov
39+
- codecov -F Travis

appveyor.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,29 @@ environment:
1212
- PYTHON: "C:\\Python35"
1313
- PYTHON: "C:\\Python36"
1414

15+
branches:
16+
only:
17+
- master
18+
19+
skip_branch_with_pr: true
20+
21+
max_jobs: 1
22+
1523
install:
16-
# We need wheel installed to build wheels
24+
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
1725
- "git submodule update --init --recursive"
18-
- "%PYTHON%\\python.exe -m pip install -U wheel"
19-
- "%PYTHON%\\python.exe -m pip install -r requirements.txt"
20-
- "%PYTHON%\\python.exe -m pip install -r requirements-dev.txt"
26+
# Check that we have the expected version and architecture for Python
27+
- "python --version"
28+
# We need wheel installed to build wheels
29+
- "pip install -U codecov pytest-cov"
30+
- "pip install -U wheel"
31+
- "pip install -r requirements.txt"
32+
- "pip install -r requirements-dev.txt"
2133

2234
build: off
2335

24-
cache: C:\Users\appveyor\pip\wheels
25-
2636
test_script:
27-
- "%python%\\Scripts\\pytest -v --cov"
37+
- "pytest -m \"not nocoverage\" --cov --cov-report xml:coverage.xml"
38+
39+
after_test:
40+
- "codecov -f coverage.xml -F Appveyor"

tests/test_bot.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
19+
import os
1920
import time
2021
from datetime import datetime, timedelta
2122
from platform import python_implementation
@@ -27,7 +28,7 @@
2728
from telegram import (Bot, Update, ChatAction, TelegramError, User, InlineKeyboardMarkup,
2829
InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent,
2930
ShippingOption, LabeledPrice)
30-
from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter, TimedOut
31+
from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter
3132
from telegram.utils.helpers import from_timestamp
3233

3334
BASE_TIME = time.time()
@@ -148,6 +149,7 @@ def test_send_contact(self, bot, chat_id):
148149
assert message.contact.first_name == first_name
149150
assert message.contact.last_name == last_name
150151

152+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (''yet)')
151153
@flaky(3, 1)
152154
@pytest.mark.timeout(10)
153155
def test_send_game(self, bot, chat_id):
@@ -191,14 +193,16 @@ def test(_, url, data, *args, **kwargs):
191193

192194
@flaky(3, 1)
193195
@pytest.mark.timeout(10)
194-
def test_get_user_profile_photos(self, bot, chat_id):
196+
def test_get_user_profile_photos(self, bot):
197+
chat_id = 12173560 # hardcoded Leandro's chat_id
195198
user_profile_photos = bot.get_user_profile_photos(chat_id)
196199

197200
assert user_profile_photos.photos[0][0].file_size == 12421
198201

199202
@flaky(3, 1)
200203
@pytest.mark.timeout(10)
201-
def test_get_one_user_profile_photo(self, bot, chat_id):
204+
def test_get_one_user_profile_photo(self, bot):
205+
chat_id = 12173560 # hardcoded Leandro's chat_id
202206
user_profile_photos = bot.get_user_profile_photos(chat_id, offset=0, limit=1)
203207
assert user_profile_photos.photos[0][0].file_size == 12421
204208

@@ -364,6 +368,7 @@ def test_get_chat_member(self, bot, channel_id):
364368
assert chat_member.status == 'administrator'
365369
assert chat_member.user.username == 'EchteEldin'
366370

371+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
367372
@flaky(3, 1)
368373
@pytest.mark.timeout(10)
369374
def test_set_game_score_1(self, bot, chat_id):
@@ -382,6 +387,7 @@ def test_set_game_score_1(self, bot, chat_id):
382387
assert message.game.photo[0].file_size == game.game.photo[0].file_size
383388
assert message.game.text != game.game.text
384389

390+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
385391
@flaky(3, 1)
386392
@pytest.mark.timeout(10)
387393
def test_set_game_score_2(self, bot, chat_id):
@@ -403,6 +409,7 @@ def test_set_game_score_2(self, bot, chat_id):
403409
assert message.game.photo[0].file_size == game.game.photo[0].file_size
404410
assert message.game.text == game.game.text
405411

412+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
406413
@flaky(3, 1)
407414
@pytest.mark.timeout(10)
408415
def test_set_game_score_3(self, bot, chat_id):
@@ -419,6 +426,7 @@ def test_set_game_score_3(self, bot, chat_id):
419426
chat_id=game.chat_id,
420427
message_id=game.message_id)
421428

429+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
422430
@flaky(3, 1)
423431
@pytest.mark.timeout(10)
424432
def test_set_game_score_4(self, bot, chat_id):
@@ -444,6 +452,7 @@ def test_set_game_score_4(self, bot, chat_id):
444452
game2 = bot.send_game(chat_id, game_short_name)
445453
assert str(score) in game2.game.text
446454

455+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
447456
@flaky(3, 1)
448457
@pytest.mark.timeout(10)
449458
def test_set_game_score_too_low_score(self, bot, chat_id):
@@ -455,6 +464,7 @@ def test_set_game_score_too_low_score(self, bot, chat_id):
455464
bot.set_game_score(user_id=chat_id, score=100,
456465
chat_id=game.chat_id, message_id=game.message_id)
457466

467+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
458468
@flaky(3, 1)
459469
@pytest.mark.timeout(10)
460470
def test_get_game_high_scores(self, bot, chat_id):

tests/test_jobqueue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
import datetime
20+
import os
2021
import time
2122
from time import sleep
2223

@@ -34,6 +35,7 @@ def job_queue(bot):
3435
jq.stop()
3536

3637

38+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason="On Appveyor precise timings are not accurate.")
3739
@flaky(10, 1) # Timings aren't quite perfect
3840
class TestJobQueue(object):
3941
result = 0

tests/test_messagequeue.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919

20+
import os
2021
from time import sleep
2122

23+
import pytest
24+
2225
import telegram.ext.messagequeue as mq
2326

2427

28+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason="On Appveyor precise timings are not accurate.")
2529
class TestDelayQueue(object):
2630
N = 128
2731
burst_limit = 30

tests/test_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def call_pre_commit_hook(hook_id):
3030

3131
@pytest.mark.nocoverage
3232
@pytest.mark.parametrize('hook_id', argvalues=('yapf', 'flake8', 'pylint'))
33-
@pytest.mark.skipif(not os.getenv('TRAVIS'), reason='Not running in travis.')
33+
@pytest.mark.skipif(not (os.getenv('TRAVIS') or os.getenv('APPVEYOR')), reason='Not running in CI')
3434
@pytest.mark.skipif(not sys.version_info[:2] == (3, 6) or python_implementation() != 'CPython',
3535
reason='Only running pre-commit-hooks on newest tested python version, '
3636
'as they are slow and consistent across platforms.')

tests/test_official.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import telegram
3232

3333
IGNORED_OBJECTS = ('ResponseParameters', 'CallbackGame')
34-
IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot'}
34+
IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot',
35+
'new_chat_member'}
36+
# TODO: New_chat_member is still in our lib but already removed from TG's docs.
3537

3638

3739
def find_next_sibling_until(tag, name, until):

tests/test_sticker.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from future.utils import PY2
2626

2727
from telegram import Sticker, PhotoSize, TelegramError, StickerSet, Audio, MaskPosition
28-
from telegram.error import BadRequest
2928

3029

3130
@pytest.fixture(scope='function')
@@ -244,6 +243,7 @@ def test_de_json(self, bot):
244243
assert sticker_set.contains_masks == self.contains_masks
245244
assert sticker_set.stickers == self.stickers
246245

246+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
247247
def test_sticker_set_to_dict(self, sticker_set):
248248
sticker_set_dict = sticker_set.to_dict()
249249

@@ -253,20 +253,23 @@ def test_sticker_set_to_dict(self, sticker_set):
253253
assert sticker_set_dict['contains_masks'] == sticker_set.contains_masks
254254
assert sticker_set_dict['stickers'][0] == sticker_set.stickers[0].to_dict()
255255

256-
@flaky(3,1)
256+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
257+
@flaky(3, 1)
257258
@pytest.mark.timeout(10)
258259
def test_bot_methods_1(self, bot, sticker_set):
259260
with open('tests/data/telegram_sticker.png', 'rb') as f:
260261
file = bot.upload_sticker_file(95205500, f)
261262
assert file
262263
assert bot.add_sticker_to_set(95205500, sticker_set.name, file.file_id, '😄')
263264

264-
@flaky(3,1)
265+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
266+
@flaky(3, 1)
265267
@pytest.mark.timeout(10)
266268
def test_bot_methods_2(self, bot, sticker_set):
267269
file_id = sticker_set.stickers[0].file_id
268270
assert bot.set_sticker_position_in_set(file_id, 1)
269271

272+
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
270273
@flaky(10, 1)
271274
@pytest.mark.timeout(10)
272275
def test_bot_methods_3(self, bot, sticker_set):

0 commit comments

Comments
 (0)