示例#1
0
文件: test_venv.py 项目: switham/tox
def test_getsupportedinterpreter(monkeypatch, newconfig, mocksession):
    config = newconfig([], """
        [testenv:python]
        basepython=%s
    """ % sys.executable)
    venv = VirtualEnv(config.envconfigs['python'], session=mocksession)
    interp = venv.getsupportedinterpreter()
    # realpath needed for debian symlinks
    assert py.path.local(interp).realpath() == py.path.local(
        sys.executable).realpath()
    monkeypatch.setattr(sys, 'platform', "win32")
    monkeypatch.setattr(venv.envconfig, 'basepython', 'jython')
    pytest.raises(tox.exception.UnsupportedInterpreter,
                  venv.getsupportedinterpreter)
    monkeypatch.undo()
    monkeypatch.setattr(venv.envconfig, "envname", "py1")
    monkeypatch.setattr(venv.envconfig, 'basepython', 'notexistingpython')
    pytest.raises(tox.exception.InterpreterNotFound,
                  venv.getsupportedinterpreter)
    monkeypatch.undo()
    # check that we properly report when no version_info is present
    info = NoInterpreterInfo(name=venv.name)
    info.executable = "something"
    monkeypatch.setattr(config.interpreters, "get_info",
                        lambda *args, **kw: info)
    pytest.raises(tox.exception.InvocationError, venv.getsupportedinterpreter)
示例#2
0
def tox_testenv_create(venv: VirtualEnv, action: action.Action) -> Any:
    clone_pdm_files(str(venv.path), str(venv.envconfig.config.toxinidir))
    config_interpreter = venv.getsupportedinterpreter()

    def patch_getcommandpath(getcommandpath):
        @functools.wraps(getcommandpath)
        def patched(self, cmd, *args, **kwargs):
            if cmd == "python":
                return config_interpreter
            return getcommandpath(self, cmd, *args, **kwargs)

        return patched

    VirtualEnv.getcommandpath = patch_getcommandpath(VirtualEnv.getcommandpath)
    if not venv.path.join(".pdm.toml").exists():
        venv._pcall(
            [
                venv.envconfig.config.option.pdm, "use", "-f",
                config_interpreter
            ],
            cwd=venv.path,
            venv=False,
            action=action,
        )
    return True
示例#3
0
def test_getsupportedinterpreter(monkeypatch, newconfig, mocksession):
    config = newconfig(
        [],
        """
        [testenv:python]
        basepython={}
    """.format(
            sys.executable
        ),
    )
    venv = VirtualEnv(config.envconfigs["python"], session=mocksession)
    interp = venv.getsupportedinterpreter()
    # realpath needed for debian symlinks
    assert py.path.local(interp).realpath() == py.path.local(sys.executable).realpath()
    monkeypatch.setattr(tox.INFO, "IS_WIN", True)
    monkeypatch.setattr(venv.envconfig, "basepython", "jython")
    with pytest.raises(tox.exception.UnsupportedInterpreter):
        venv.getsupportedinterpreter()
    monkeypatch.undo()
    monkeypatch.setattr(venv.envconfig, "envname", "py1")
    monkeypatch.setattr(venv.envconfig, "basepython", "notexistingpython")
    with pytest.raises(tox.exception.InterpreterNotFound):
        venv.getsupportedinterpreter()
    monkeypatch.undo()
    # check that we properly report when no version_info is present
    info = NoInterpreterInfo(name=venv.name)
    info.executable = "something"
    monkeypatch.setattr(config.interpreters, "get_info", lambda *args, **kw: info)
    with pytest.raises(tox.exception.InvocationError):
        venv.getsupportedinterpreter()
示例#4
0
def tox_runenvreport(venv: VirtualEnv, action: action.Action):
    if not detect_pdm_files(venv.path):
        return
    command = venv.envconfig.list_dependencies_command
    for i, arg in enumerate(command):
        if arg == "python":
            command[i] = venv.getsupportedinterpreter()
    venv.envconfig.list_dependencies_command.extend([
        "--path",
        get_env_lib_path(venv.envconfig.config.option.pdm, venv.path)
    ])
示例#5
0
def tox_package(session: session.Session, venv: VirtualEnv) -> Any:
    with venv.new_action("buildpkg") as action:
        tox_testenv_create(venv, action)
    if not detect_pdm_files(venv.path):
        return
    if not hasattr(session, "package"):
        session.package, session.dist = get_package(session, venv)
    # Patch the install command to install to local __pypackages__ folder
    for i, arg in enumerate(venv.envconfig.install_command):
        if arg == "python":
            venv.envconfig.install_command[i] = venv.getsupportedinterpreter()
    venv.envconfig.install_command.extend(
        ["-t",
         get_env_lib_path(venv.envconfig.config.option.pdm, venv.path)])
    return session.package