Exemple #1
0
def test_locate_via_py(monkeypatch):
    from tox.interpreters import locate_via_py

    def fake_find_exe(exe):
        assert exe == "py"
        return "py"

    def fake_popen(cmd, stdout, stderr):
        fake_popen.last_call = cmd[:3]

        # need to pipe all stdout to collect the version information & need to
        # do the same for stderr output to avoid it being forwarded as the
        # current process's output, e.g. when the python launcher reports the
        # requested Python interpreter not being installed on the system
        assert stdout is subprocess.PIPE
        assert stderr is subprocess.PIPE

        class proc:
            returncode = 0

            @staticmethod
            def communicate():
                return sys.executable.encode(), None

        return proc

    monkeypatch.setattr(distutils.spawn, "find_executable", fake_find_exe)
    monkeypatch.setattr(subprocess, "Popen", fake_popen)
    assert locate_via_py("3", "6") == sys.executable
    assert fake_popen.last_call == ("py", "-3.6", "-c")
    assert locate_via_py("3") == sys.executable
    assert fake_popen.last_call == ("py", "-3", "-c")
Exemple #2
0
def test_locate_via_py(monkeypatch):
    from tox.interpreters import locate_via_py

    def fake_find_exe(exe):
        assert exe == 'py'
        return 'py'

    def fake_popen(cmd, stdout, stderr):
        assert cmd[:3] == ('py', '-3.2', '-c')

        # need to pipe all stdout to collect the version information & need to
        # do the same for stderr output to avoid it being forwarded as the
        # current process's output, e.g. when the python launcher reports the
        # requested Python interpreter not being installed on the system
        assert stdout is subprocess.PIPE
        assert stderr is subprocess.PIPE

        class proc:
            returncode = 0

            @staticmethod
            def communicate():
                return sys.executable.encode(), None

        return proc

    # Monkeypatch modules to return our faked value
    monkeypatch.setattr(distutils.spawn, 'find_executable', fake_find_exe)
    monkeypatch.setattr(subprocess, 'Popen', fake_popen)
    assert locate_via_py('3', '2') == sys.executable
Exemple #3
0
def test_locate_via_py(monkeypatch):
    from tox.interpreters import locate_via_py

    def fake_find_exe(exe):
        assert exe == 'py'
        return 'py'

    def fake_popen(cmd, stdout):
        assert cmd[:3] == ('py', '-3.2', '-c')

        class proc:
            returncode = 0

            @staticmethod
            def communicate():
                return sys.executable.encode(), None
        return proc

    # Monkeypatch modules to return our faked value
    monkeypatch.setattr(distutils.spawn, 'find_executable', fake_find_exe)
    monkeypatch.setattr(subprocess, 'Popen', fake_popen)
    assert locate_via_py('3', '2') == sys.executable