From dd20237f552a61c7369ff5f94453ac2117dfef38 Mon Sep 17 00:00:00 2001 From: Eldinnie Date: Thu, 14 Sep 2017 17:54:00 +0200 Subject: [PATCH] Enable appveyor (#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 --- .travis.yml | 2 +- appveyor.yml | 27 ++++++++++++++++++++------- tests/test_bot.py | 16 +++++++++++++--- tests/test_jobqueue.py | 2 ++ tests/test_messagequeue.py | 4 ++++ tests/test_meta.py | 2 +- tests/test_official.py | 4 +++- tests/test_sticker.py | 9 ++++++--- 8 files changed, 50 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f1e8f6ba..894e5c92e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,4 +36,4 @@ script: after_success: - coverage combine - - codecov \ No newline at end of file + - codecov -F Travis \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index dfe650c78..47d1a5741 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,16 +12,29 @@ environment: - PYTHON: "C:\\Python35" - PYTHON: "C:\\Python36" +branches: + only: + - master + +skip_branch_with_pr: true + +max_jobs: 1 + install: - # We need wheel installed to build wheels + - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" - "git submodule update --init --recursive" - - "%PYTHON%\\python.exe -m pip install -U wheel" - - "%PYTHON%\\python.exe -m pip install -r requirements.txt" - - "%PYTHON%\\python.exe -m pip install -r requirements-dev.txt" + # Check that we have the expected version and architecture for Python + - "python --version" + # We need wheel installed to build wheels + - "pip install -U codecov pytest-cov" + - "pip install -U wheel" + - "pip install -r requirements.txt" + - "pip install -r requirements-dev.txt" build: off -cache: C:\Users\appveyor\pip\wheels - test_script: - - "%python%\\Scripts\\pytest -v --cov" + - "pytest -m \"not nocoverage\" --cov --cov-report xml:coverage.xml" + +after_test: + - "codecov -f coverage.xml -F Appveyor" diff --git a/tests/test_bot.py b/tests/test_bot.py index f05e423ba..2067cbe15 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -16,6 +16,7 @@ # # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. +import os import time from datetime import datetime, timedelta from platform import python_implementation @@ -27,7 +28,7 @@ from future.utils import string_types from telegram import (Bot, Update, ChatAction, TelegramError, User, InlineKeyboardMarkup, InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent, ShippingOption, LabeledPrice) -from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter, TimedOut +from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter from telegram.utils.helpers import from_timestamp BASE_TIME = time.time() @@ -148,6 +149,7 @@ class TestBot(object): assert message.contact.first_name == first_name assert message.contact.last_name == last_name + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (''yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_send_game(self, bot, chat_id): @@ -191,14 +193,16 @@ class TestBot(object): @flaky(3, 1) @pytest.mark.timeout(10) - def test_get_user_profile_photos(self, bot, chat_id): + def test_get_user_profile_photos(self, bot): + chat_id = 12173560 # hardcoded Leandro's chat_id user_profile_photos = bot.get_user_profile_photos(chat_id) assert user_profile_photos.photos[0][0].file_size == 12421 @flaky(3, 1) @pytest.mark.timeout(10) - def test_get_one_user_profile_photo(self, bot, chat_id): + def test_get_one_user_profile_photo(self, bot): + chat_id = 12173560 # hardcoded Leandro's chat_id user_profile_photos = bot.get_user_profile_photos(chat_id, offset=0, limit=1) assert user_profile_photos.photos[0][0].file_size == 12421 @@ -364,6 +368,7 @@ class TestBot(object): assert chat_member.status == 'administrator' assert chat_member.user.username == 'EchteEldin' + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_set_game_score_1(self, bot, chat_id): @@ -382,6 +387,7 @@ class TestBot(object): assert message.game.photo[0].file_size == game.game.photo[0].file_size assert message.game.text != game.game.text + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_set_game_score_2(self, bot, chat_id): @@ -403,6 +409,7 @@ class TestBot(object): assert message.game.photo[0].file_size == game.game.photo[0].file_size assert message.game.text == game.game.text + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_set_game_score_3(self, bot, chat_id): @@ -419,6 +426,7 @@ class TestBot(object): chat_id=game.chat_id, message_id=game.message_id) + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_set_game_score_4(self, bot, chat_id): @@ -444,6 +452,7 @@ class TestBot(object): game2 = bot.send_game(chat_id, game_short_name) assert str(score) in game2.game.text + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_set_game_score_too_low_score(self, bot, chat_id): @@ -455,6 +464,7 @@ class TestBot(object): bot.set_game_score(user_id=chat_id, score=100, chat_id=game.chat_id, message_id=game.message_id) + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)') @flaky(3, 1) @pytest.mark.timeout(10) def test_get_game_high_scores(self, bot, chat_id): diff --git a/tests/test_jobqueue.py b/tests/test_jobqueue.py index a3381858d..4963132cb 100644 --- a/tests/test_jobqueue.py +++ b/tests/test_jobqueue.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. import datetime +import os import time from time import sleep @@ -34,6 +35,7 @@ def job_queue(bot): jq.stop() +@pytest.mark.skipif(os.getenv('APPVEYOR'), reason="On Appveyor precise timings are not accurate.") @flaky(10, 1) # Timings aren't quite perfect class TestJobQueue(object): result = 0 diff --git a/tests/test_messagequeue.py b/tests/test_messagequeue.py index 50e0def08..758680fef 100644 --- a/tests/test_messagequeue.py +++ b/tests/test_messagequeue.py @@ -17,11 +17,15 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. +import os from time import sleep +import pytest + import telegram.ext.messagequeue as mq +@pytest.mark.skipif(os.getenv('APPVEYOR'), reason="On Appveyor precise timings are not accurate.") class TestDelayQueue(object): N = 128 burst_limit = 30 diff --git a/tests/test_meta.py b/tests/test_meta.py index 8ccf6f672..deecba3cb 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -30,7 +30,7 @@ def call_pre_commit_hook(hook_id): @pytest.mark.nocoverage @pytest.mark.parametrize('hook_id', argvalues=('yapf', 'flake8', 'pylint')) -@pytest.mark.skipif(not os.getenv('TRAVIS'), reason='Not running in travis.') +@pytest.mark.skipif(not (os.getenv('TRAVIS') or os.getenv('APPVEYOR')), reason='Not running in CI') @pytest.mark.skipif(not sys.version_info[:2] == (3, 6) or python_implementation() != 'CPython', reason='Only running pre-commit-hooks on newest tested python version, ' 'as they are slow and consistent across platforms.') diff --git a/tests/test_official.py b/tests/test_official.py index 69a542999..0931c45bd 100644 --- a/tests/test_official.py +++ b/tests/test_official.py @@ -31,7 +31,9 @@ from telegram.vendor.ptb_urllib3 import urllib3 import telegram IGNORED_OBJECTS = ('ResponseParameters', 'CallbackGame') -IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot'} +IGNORED_PARAMETERS = {'self', 'args', 'kwargs', 'read_latency', 'network_delay', 'timeout', 'bot', + 'new_chat_member'} +# TODO: New_chat_member is still in our lib but already removed from TG's docs. def find_next_sibling_until(tag, name, until): diff --git a/tests/test_sticker.py b/tests/test_sticker.py index cc394a88f..d6aa68b23 100644 --- a/tests/test_sticker.py +++ b/tests/test_sticker.py @@ -25,7 +25,6 @@ from flaky import flaky from future.utils import PY2 from telegram import Sticker, PhotoSize, TelegramError, StickerSet, Audio, MaskPosition -from telegram.error import BadRequest @pytest.fixture(scope='function') @@ -244,6 +243,7 @@ class TestStickerSet(object): assert sticker_set.contains_masks == self.contains_masks assert sticker_set.stickers == self.stickers + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)') def test_sticker_set_to_dict(self, sticker_set): sticker_set_dict = sticker_set.to_dict() @@ -253,7 +253,8 @@ class TestStickerSet(object): assert sticker_set_dict['contains_masks'] == sticker_set.contains_masks assert sticker_set_dict['stickers'][0] == sticker_set.stickers[0].to_dict() - @flaky(3,1) + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)') + @flaky(3, 1) @pytest.mark.timeout(10) def test_bot_methods_1(self, bot, sticker_set): with open('tests/data/telegram_sticker.png', 'rb') as f: @@ -261,12 +262,14 @@ class TestStickerSet(object): assert file assert bot.add_sticker_to_set(95205500, sticker_set.name, file.file_id, '😄') - @flaky(3,1) + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)') + @flaky(3, 1) @pytest.mark.timeout(10) def test_bot_methods_2(self, bot, sticker_set): file_id = sticker_set.stickers[0].file_id assert bot.set_sticker_position_in_set(file_id, 1) + @pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)') @flaky(10, 1) @pytest.mark.timeout(10) def test_bot_methods_3(self, bot, sticker_set):