コード例 #1
0
def test_tox_get_python_executable():
    class envconfig:
        basepython = sys.executable
        envname = "pyxx"

    p = tox_get_python_executable(envconfig)
    assert p == py.path.local(sys.executable)
    for ver in "2.7 3.4 3.5 3.6".split():
        name = "python%s" % ver
        if sys.platform == "win32":
            pydir = "python%s" % ver.replace(".", "")
            x = py.path.local(r"c:\%s" % pydir)
            print(x)
            if not x.check():
                continue
        else:
            if not py.path.local.sysfind(name):
                continue
        envconfig.basepython = name
        p = tox_get_python_executable(envconfig)
        assert p
        popen = subprocess.Popen([str(p), '-V'],
                                 stderr=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
        stdout, stderr = popen.communicate()
        assert not stdout or not stderr
        assert ver in stderr.decode('ascii') or ver in stdout.decode('ascii')
コード例 #2
0
def test_tox_get_python_executable():
    class envconfig:
        basepython = sys.executable
        envname = "pyxx"

    p = tox_get_python_executable(envconfig)
    assert p == py.path.local(sys.executable)
    for major, minor in tox.PYTHON.CPYTHON_VERSION_TUPLES:
        name = "python{}.{}".format(major, minor)
        if tox.INFO.IS_WIN:
            pydir = "python{}{}".format(major, minor)
            x = py.path.local(r"c:\{}".format(pydir))
            print(x)
            if not x.check():
                continue
        else:
            if not py.path.local.sysfind(name):
                continue
        envconfig.basepython = name
        p = tox_get_python_executable(envconfig)
        assert p
        popen = subprocess.Popen([str(p), "-V"],
                                 stderr=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
        stdout, stderr = popen.communicate()
        assert not stdout or not stderr
        all_output = stderr.decode("ascii") + stdout.decode("ascii")
        assert "{}.{}".format(major, minor) in all_output
コード例 #3
0
def test_find_executable_extra(monkeypatch):
    @staticmethod
    def sysfind(x):
        return "hello"
    monkeypatch.setattr(py.path.local, "sysfind", sysfind)

    class envconfig:
        basepython = "1lk23j"
        envname = "pyxx"

    t = tox_get_python_executable(envconfig)
    assert t == "hello"
コード例 #4
0
ファイル: test_interpreters.py プロジェクト: zeroshift/tox
def test_find_alias_on_path(monkeypatch, tmp_path):
    reporter.update_default_reporter(Verbosity.DEFAULT, Verbosity.DEBUG)
    magic = tmp_path / "magic{}".format(os.path.splitext(sys.executable)[1])
    os.symlink(sys.executable, str(magic))
    monkeypatch.setenv(
        str("PATH"),
        os.pathsep.join(([str(tmp_path)] + os.environ.get(str("PATH"), "").split(os.pathsep))),
    )

    class envconfig:
        basepython = "magic"
        envname = "pyxx"

    detected = py.path.local.sysfind("magic")
    assert detected

    t = tox_get_python_executable(envconfig).lower()
    assert t == str(magic).lower()
コード例 #5
0
ファイル: test_interpreters.py プロジェクト: znewman01/tox
def test_tox_get_python_executable(mocker):
    class envconfig:
        basepython = sys.executable
        envname = "pyxx"
        config = mocker.MagicMock()
        config.return_value.option.return_value.discover = []

    def get_exe(name):
        envconfig.basepython = name
        p = tox_get_python_executable(envconfig)
        assert p
        return str(p)

    def assert_version_in_output(exe, version):
        out = subprocess.check_output((exe, "-V"), stderr=subprocess.STDOUT)
        assert version in out.decode()

    p = tox_get_python_executable(envconfig)
    assert p == py.path.local(sys.executable)
    for major, minor in [(2, 7), (3, 5), (3, 6), (3, 7), (3, 8)]:
        name = "python{}.{}".format(major, minor)
        if tox.INFO.IS_WIN:
            pydir = "python{}{}".format(major, minor)
            x = py.path.local(r"c:\{}".format(pydir))
            if not x.check():
                continue
        else:
            if not py.path.local.sysfind(name) or subprocess.call(
                (name, "-c", "")):
                continue
        exe = get_exe(name)
        assert_version_in_output(exe, "{}.{}".format(major, minor))
    has_py_exe = py.path.local.sysfind("py") is not None
    for major in (2, 3):
        name = "python{}".format(major)
        if has_py_exe:
            error_code = subprocess.call(("py", "-{}".format(major), "-c", ""))
            if error_code:
                continue
        elif not py.path.local.sysfind(name):
            continue

        exe = get_exe(name)
        assert_version_in_output(exe, str(major))
コード例 #6
0
ファイル: test_interpreters.py プロジェクト: pvicente/tox
def test_tox_get_python_executable():
    class envconfig:
        basepython = sys.executable
        envname = "pyxx"

    def get_exe(name):
        envconfig.basepython = name
        p = tox_get_python_executable(envconfig)
        assert p
        return str(p)

    def assert_version_in_output(exe, version):
        out = subprocess.check_output((exe, "-V"), stderr=subprocess.STDOUT)
        assert version in out.decode()

    p = tox_get_python_executable(envconfig)
    assert p == py.path.local(sys.executable)
    for major, minor in tox.PYTHON.CPYTHON_VERSION_TUPLES:
        name = "python{}.{}".format(major, minor)
        if tox.INFO.IS_WIN:
            pydir = "python{}{}".format(major, minor)
            x = py.path.local(r"c:\{}".format(pydir))
            if not x.check():
                continue
        else:
            if not py.path.local.sysfind(name) or subprocess.call(
                (name, "-c", "")):
                continue
        exe = get_exe(name)
        assert_version_in_output(exe, "{}.{}".format(major, minor))

    for major in (2, 3):
        name = "python{}".format(major)
        if tox.INFO.IS_WIN:
            error_code = subprocess.call(("py", "-{}".format(major), "-c", ""))
            if error_code:
                continue
        elif not py.path.local.sysfind(name):
            continue

        exe = get_exe(name)
        assert_version_in_output(exe, str(major))
コード例 #7
0
ファイル: test_interpreters.py プロジェクト: pvicente/tox
 def get_exe(name):
     envconfig.basepython = name
     p = tox_get_python_executable(envconfig)
     assert p
     return str(p)