Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the same config file as Tox #59

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/tox_travis/after.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import json
import time
import py

from tox.config import _split_env as split_env
try:
Expand Down Expand Up @@ -32,18 +31,18 @@ def subcommand_test(self):
retcode = real_subcommand_test(self)
if retcode == 0 and self.config.option.travis_after:
# No need to run if the tests failed anyway
travis_after(self.config.envlist)
travis_after(self.config.envlist, self.config._cfg)
return retcode
tox.session.Session.subcommand_test = subcommand_test


def travis_after(envlist):
def travis_after(envlist, ini):
"""Wait for all jobs to finish, then exit successfully."""
# after-all disabled for pull requests
if os.environ.get('TRAVIS_PULL_REQUEST', 'false') != 'false':
return

if not after_config_matches(envlist):
if not after_config_matches(envlist, ini):
return # This is not the one that needs to wait

github_token = os.environ.get('GITHUB_TOKEN')
Expand Down Expand Up @@ -77,10 +76,9 @@ def travis_after(envlist):
print('All required jobs were successful.')


def after_config_matches(envlist):
def after_config_matches(envlist, ini):
"""Determine if this job should wait for the others."""
config = py.iniconfig.IniConfig('tox.ini')
section = config.sections.get('travis:after', {})
section = ini.sections.get('travis:after', {})

if not section:
return False # Never wait if it's not configured
Expand Down
6 changes: 2 additions & 4 deletions src/tox_travis/toxenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import sys
import re
import py
import tox.config
from tox.config import _split_env as split_env
from .utils import TRAVIS_FACTORS, parse_dict
Expand All @@ -15,7 +14,7 @@ def default_toxenv(config):
if 'TOXENV' in os.environ or config.option.env:
return # Skip any processing if already set

ini = py.iniconfig.IniConfig('tox.ini')
ini = config._cfg

# Find the envs that tox knows about
declared_envs = get_declared_envs(ini)
Expand Down Expand Up @@ -235,8 +234,7 @@ def env_matches(declared, desired):

def override_ignore_outcome(config):
"""Override ignore_outcome if unignore_outcomes is set to True."""
tox_config = py.iniconfig.IniConfig('tox.ini')
travis_reader = tox.config.SectionReader("travis", tox_config)
travis_reader = tox.config.SectionReader("travis", config._cfg)
if travis_reader.getbool('unignore_outcomes', False):
for envconfig in config.envconfigs.values():
envconfig.ignore_outcome = False
16 changes: 8 additions & 8 deletions tests/test_after.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_pull_request(self, mocker, monkeypatch, capsys):
monkeypatch.setenv('TRAVIS', 'true')
monkeypatch.setenv('TRAVIS_PULL_REQUEST', '1')

travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

out, err = capsys.readouterr()
assert out == ''
Expand All @@ -25,7 +25,7 @@ def test_no_github_token(self, mocker, monkeypatch, capsys):
return_value=True)
monkeypatch.setenv('TRAVIS', 'true')
with pytest.raises(SystemExit) as excinfo:
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

assert excinfo.value.code == 32
out, err = capsys.readouterr()
Expand All @@ -38,7 +38,7 @@ def test_travis_environment_build_id(self, mocker, monkeypatch, capsys):
monkeypatch.setenv('TRAVIS', 'true')
monkeypatch.setenv('GITHUB_TOKEN', 'spamandeggs')
with pytest.raises(SystemExit) as excinfo:
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

assert excinfo.value.code == 34
out, err = capsys.readouterr()
Expand All @@ -52,7 +52,7 @@ def test_travis_environment_job_number(self, mocker, monkeypatch, capsys):
monkeypatch.setenv('GITHUB_TOKEN', 'spamandeggs')
monkeypatch.setenv('TRAVIS_BUILD_ID', '1234')
with pytest.raises(SystemExit) as excinfo:
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

assert excinfo.value.code == 34
out, err = capsys.readouterr()
Expand All @@ -69,7 +69,7 @@ def test_travis_environment_api_url(self, mocker, monkeypatch, capsys):
# TRAVIS_API_URL is set to a reasonable default
monkeypatch.setenv('TRAVIS_API_URL', '')
with pytest.raises(SystemExit) as excinfo:
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

assert excinfo.value.code == 34
out, err = capsys.readouterr()
Expand All @@ -86,7 +86,7 @@ def test_travis_env_polling_interval(self, mocker, monkeypatch, capsys):
# TRAVIS_POLLING_INTERVAL is set to a reasonable default
monkeypatch.setenv('TRAVIS_POLLING_INTERVAL', 'xbe')
with pytest.raises(SystemExit) as excinfo:
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

assert excinfo.value.code == 33
out, err = capsys.readouterr()
Expand Down Expand Up @@ -186,7 +186,7 @@ def get_json(url, auth=None, data=None):
get_json.responses = iter(responses)

mocker.patch('tox_travis.after.get_json', side_effect=get_json)
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())
out, err = capsys.readouterr()
assert 'All required jobs were successful.' in out

Expand Down Expand Up @@ -289,7 +289,7 @@ def get_json(url, auth=None, data=None):
mocker.patch('tox_travis.after.get_json', side_effect=get_json)

with pytest.raises(SystemExit) as excinfo:
travis_after(mocker.Mock())
travis_after(mocker.Mock(), mocker.Mock())

assert excinfo.value.code == 35
out, err = capsys.readouterr()
Expand Down
33 changes: 23 additions & 10 deletions tests/test_toxenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,33 @@
class TestToxEnv:
"""Test the logic to automatically configure TOXENV with Travis."""

def tox_envs(self):
def tox_envs(self, **kwargs):
"""Find the envs that tox sees."""
returncode, stdout, stderr = self.tox_envs_raw()
returncode, stdout, stderr = self.tox_envs_raw(**kwargs)
assert returncode == 0, stderr
return [env for env in stdout.strip().split('\n')]

def tox_envs_raw(self):
def tox_envs_raw(self, ini_filename=None):
"""Return the raw output of finding what tox sees."""
return self.call_raw(['tox', '-l'])
command = ['tox', '-l']
if ini_filename is not None:
command += ['-c', ini_filename]
return self.call_raw(command)

def tox_config(self):
def tox_config(self, **kwargs):
"""Returns the configuration per configuration as computed by tox."""
returncode, stdout, stderr = self.tox_config_raw()
returncode, stdout, stderr = self.tox_config_raw(**kwargs)
assert returncode == 0, stderr
ini = "[global]\n" + re.sub(
re.compile(r'^\s+', re.MULTILINE), '', stdout)
return py.iniconfig.IniConfig('', data=ini)

def tox_config_raw(self):
def tox_config_raw(self, ini_filename=None):
"""Return the raw output of finding the complex tox env config."""
return self.call_raw(['tox', '--showconfig'])
command = ['tox', '--showconfig']
if ini_filename is not None:
command += ['-c', ini_filename]
return self.call_raw(command)

def call_raw(self, command):
"""Return the raw output of the given command."""
Expand All @@ -152,10 +158,11 @@ def call_raw(self, command):
def configure(self, tmpdir, monkeypatch, tox_ini,
version=None, major=None, minor=None,
travis_version=None, travis_os=None,
travis_language=None, env=None):
travis_language=None, env=None,
ini_filename='tox.ini'):
"""Configure the environment for running a test."""
origdir = tmpdir.chdir()
tmpdir.join('tox.ini').write(tox_ini)
tmpdir.join(ini_filename).write(tox_ini)
tmpdir.join('.coveragerc').write(coverage_config)

if version or travis_version or travis_os or travis_language:
Expand Down Expand Up @@ -202,6 +209,12 @@ def test_not_travis(self, tmpdir, monkeypatch):
]
assert self.tox_envs() == expected

def test_travis_config_filename(self, tmpdir, monkeypatch):
"""Give the correct env for CPython 2.7."""
with self.configure(tmpdir, monkeypatch, tox_ini, 'CPython', 3, 6,
ini_filename='spam.ini'):
assert self.tox_envs(ini_filename='spam.ini') == ['py36']

def test_travis_default_26(self, tmpdir, monkeypatch):
"""Give the correct env for CPython 2.6."""
with self.configure(tmpdir, monkeypatch, tox_ini, 'CPython', 2, 6):
Expand Down