From 3f4571d9e9a86e59c665341a7197e2bee6178c82 Mon Sep 17 00:00:00 2001 From: joo Date: Fri, 19 May 2017 11:58:14 +0100 Subject: [PATCH] Update testing configuration: (1) Add py35 job to Travis. (2) To address issue #57: run tests that connect to Mojang's auth server exactly once, during the py35 job. (3) Measure coverage exactly once, during the py35 job; always submit the result to coveralls. (4) Fix miscellaneous errors in generate_travis_yml.py. --- .travis.yml | 8 ++++---- bin/generate_travis_yml.py | 14 ++++++++----- tests/test_authentication.py | 11 +++++++++++ tox.ini | 38 +++++++++++++++++++----------------- 4 files changed, 44 insertions(+), 27 deletions(-) mode change 100644 => 100755 bin/generate_travis_yml.py diff --git a/.travis.yml b/.travis.yml index 3400893..431a158 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: python -python: 2.7 +python: 3.5 env: - TOX_ENV=py27 - TOX_ENV=py33 - TOX_ENV=py34 + - TOX_ENV=py35 - TOX_ENV=pypy - - TOX_ENV=cover - TOX_ENV=flake8 - TOX_ENV=pylint-errors - TOX_ENV=pylint-full @@ -15,7 +15,7 @@ install: - pip install python-coveralls script: - tox -e $TOX_ENV -after_success: - - if [ "$TOX_ENV" = "py27" ]; then tox -e coveralls; fi +after_script: + - if [ "$TOX_ENV" = "py35" ]; then tox -e coveralls; fi notifications: email: false diff --git a/bin/generate_travis_yml.py b/bin/generate_travis_yml.py old mode 100644 new mode 100755 index 4ad4024..387d0c2 --- a/bin/generate_travis_yml.py +++ b/bin/generate_travis_yml.py @@ -1,12 +1,16 @@ +#!/usr/bin/env python # flake8: noqa +import sys import os -os.chdir("..") +import os.path +from tox.config import parseconfig -from tox._config import parseconfig +# This file is in pyCraft/bin/; it needs to execute in pyCraft/. +os.chdir(os.path.join(os.path.dirname(__file__), "..")) print("language: python") -print("python: 2.7") +print("python: 3.5") print("env:") for env in parseconfig(None, 'tox').envlist: print(" - TOX_ENV=%s" % env) @@ -15,7 +19,7 @@ print(" - pip install tox") print(" - pip install python-coveralls") print("script:") print(" - tox -e $TOX_ENV") -print("after_success:") -print(' - if [ "$TOX_ENV" = "py27 ]; then tox -e coveralls; fi') +print("after_script:") +print(' - if [ "$TOX_ENV" = "py35" ]; then tox -e coveralls; fi') print("notifications:") print(" email: false") diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 9103545..3e9b952 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -7,6 +7,7 @@ from minecraft.exceptions import YggdrasilError import requests import json import unittest +import os from .compat import mock FAKE_DATA = { @@ -56,6 +57,14 @@ def should_skip_cred_test(): return False +def should_run_internet_tests(): + """ + Returns `True` if tests involving access to Internet resources + should *not* be skipped. Otherwise returns `False`. + """ + return os.environ.get('PYCRAFT_RUN_INTERNET_TESTS') + + class InitProfile(unittest.TestCase): def test_init_no_values(self): p = Profile() @@ -194,6 +203,8 @@ class AuthenticateAuthenticationToken(unittest.TestCase): self.assertTrue(resp) +@unittest.skipUnless(should_run_internet_tests(), + "Tests involving Internet access are disabled.") class MakeRequest(unittest.TestCase): def test_make_request_http_method(self): res = _make_request(AUTHSERVER, "authenticate", {"Billy": "Bob"}) diff --git a/tox.ini b/tox.ini index 6af2534..ceaa071 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py27, py33, py34, py35, py36, pypy, cover, flake8, pylint-errors, pylint-full, verify-manifest +envlist = py27, py33, py34, py35, pypy, flake8, pylint-errors, pylint-full, verify-manifest [testenv] commands = nosetests @@ -15,20 +15,7 @@ deps = cryptography future -[testenv:py27] -deps = - {[testenv]deps} - mock - -[testenv:pypy] -deps = - {[testenv]deps} - mock - [testenv:cover] -basepython = python3.5 -commands = - nosetests --with-xunit --with-xcoverage --cover-package=minecraft --nocapture --cover-erase --cover-inclusive --cover-tests --cover-branches --cover-min-percentage=60 deps = {[testenv]deps} coverage @@ -36,14 +23,29 @@ deps = [testenv:coveralls] passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH -basepython = {[testenv:cover]basepython} commands = - {[testenv:cover]commands} coveralls deps = - {[testenv:cover]deps} coveralls +[testenv:py27] +deps = + {[testenv]deps} + mock + +[testenv:py35] +setenv = + PYCRAFT_RUN_INTERNET_TESTS=1 +commands = + nosetests --with-xunit --with-xcoverage --cover-package=minecraft --cover-erase --cover-inclusive --cover-tests --cover-branches --cover-min-percentage=60 +deps = + {[testenv:cover]deps} + +[testenv:pypy] +deps = + {[testenv]deps} + mock + [testenv:flake8] basepython = python3.5 commands = @@ -82,4 +84,4 @@ deps = check-manifest commands = check-manifest - +