<commit_before>import os
import subprocess


tox_ini = b"""
[tox]
envlist = py26, py27, py32, py33, py34, pypy, pypy3, docs
"""

tox_ini_override = tox_ini + b"""
[tox:travis]
2.7 = py27, docs
"""

tox_ini_factors = b"""
[tox]
envlist = py34, py34-docs, py34-django
"""

tox_ini_factors_override = tox_ini_factors + b"""
[tox:travis]
2.7 = py27-django
"""

tox_ini_django_factors = b"""
[tox]
envlist = py{27,34}-django, other

[tox:travis]
2.7 = django
3.4 = other
"""


class TestToxTravis:
    def tox_envs(self):
        output = subprocess.Popen(
            ['tox', '-l'], stdout=subprocess.PIPE).communicate()[0]
        return set(output.decode('utf-8').strip().split())

    def test_not_travis(self, tmpdir):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        expected = set([
            'py26', 'py27', 'py32', 'py33', 'py34',
            'pypy', 'pypy3', 'docs',
        ])

        assert self.tox_envs() == expected

    def test_travis_default_26(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.6')

        assert self.tox_envs() == set(['py26'])

    def test_travis_default_27(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == set(['py27'])

    def test_travis_default_32(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.2')

        assert self.tox_envs() == set(['py32'])

    def test_travis_default_33(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.3')

        assert self.tox_envs() == set(['py33'])

    def test_travis_default_34(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.4')

        assert self.tox_envs() == set(['py34'])

    def test_travis_default_pypy(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', 'pypy')

        assert self.tox_envs() == set(['pypy'])

    def test_travis_default_pypy3(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', 'pypy3')

        assert self.tox_envs() == set(['pypy3'])

    def test_travis_override(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_override)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == set(['py27', 'docs'])

    def test_respect_overridden_toxenv(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')
        monkeypatch.setenv('TOXENV', 'py32')

        assert self.tox_envs() == set(['py32'])

    def test_keep_if_no_match(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == set(['py27'])

    def test_default_tox_ini_overrides(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_factors_override)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == set(['py27-django'])

    def test_factors(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.4')

        assert self.tox_envs() == set(['py34', 'py34-docs', 'py34-django'])

    def test_django_factors(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_django_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == set(['py27-django', 'py34-django'])

    def test_non_python_factor(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_django_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.4')

        assert self.tox_envs() == set(['other'])
<commit_msg>Should preserve tox's ordering<commit_after>import os
import subprocess


tox_ini = b"""
[tox]
envlist = py26, py27, py32, py33, py34, pypy, pypy3, docs
"""

tox_ini_override = tox_ini + b"""
[tox:travis]
2.7 = py27, docs
"""

tox_ini_factors = b"""
[tox]
envlist = py34, py34-docs, py34-django
"""

tox_ini_factors_override = tox_ini_factors + b"""
[tox:travis]
2.7 = py27-django
"""

tox_ini_django_factors = b"""
[tox]
envlist = py{27,34}-django, other

[tox:travis]
2.7 = django
3.4 = other
"""


class TestToxTravis:
    def tox_envs(self):
        """Find the envs that tox sees."""
        output = subprocess.Popen(
            ['tox', '-l'], stdout=subprocess.PIPE).communicate()[0]
        return output.decode('utf-8').strip().split()

    def test_not_travis(self, tmpdir):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        expected = [
            'py26', 'py27', 'py32', 'py33', 'py34',
            'pypy', 'pypy3', 'docs',
        ]

        assert self.tox_envs() == expected

    def test_travis_default_26(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.6')

        assert self.tox_envs() == ['py26']

    def test_travis_default_27(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == ['py27']

    def test_travis_default_32(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.2')

        assert self.tox_envs() == ['py32']

    def test_travis_default_33(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.3')

        assert self.tox_envs() == ['py33']

    def test_travis_default_34(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.4')

        assert self.tox_envs() == ['py34']

    def test_travis_default_pypy(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', 'pypy')

        assert self.tox_envs() == ['pypy']

    def test_travis_default_pypy3(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', 'pypy3')

        assert self.tox_envs() == ['pypy3']

    def test_travis_override(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_override)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == ['py27', 'docs']

    def test_respect_overridden_toxenv(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')
        monkeypatch.setenv('TOXENV', 'py32')

        assert self.tox_envs() == ['py32']

    def test_keep_if_no_match(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == ['py27']

    def test_default_tox_ini_overrides(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_factors_override)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == ['py27-django']

    def test_factors(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.4')

        assert self.tox_envs() == ['py34', 'py34-docs', 'py34-django']

    def test_django_factors(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_django_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '2.7')

        assert self.tox_envs() == ['py27-django', 'py34-django']

    def test_non_python_factor(self, tmpdir, monkeypatch):
        os.chdir(str(tmpdir))
        tmpdir.join('tox.ini').write(tox_ini_django_factors)

        monkeypatch.setenv('TRAVIS', 'true')
        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', '3.4')

        assert self.tox_envs() == ['other']

{'fraction_non_alphanumeric': 0.16152519639777735, 'fraction_numerical': 0.021651657405633264, 'mean_word_length': 3.259077927376581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3665564', 'n_tokens_mistral': 4258, 'n_tokens_neox': 3850, 'n_words': 536}