Exemple #1
0
def test_create(mocksession, newconfig):
    config = newconfig(
        [],
        """\
        [testenv:py123]
        """,
    )
    envconfig = config.envconfigs["py123"]
    mocksession.new_config(config)
    venv = mocksession.getvenv("py123")
    assert venv.path == envconfig.envdir
    assert not venv.path.check()
    with mocksession.newaction(venv.name, "getenv") as action:
        tox_testenv_create(action=action, venv=venv)
    pcalls = mocksession._pcalls
    assert len(pcalls) >= 1
    args = pcalls[0].args
    module = "venv" if use_builtin_venv(venv) else "virtualenv"
    assert module == str(args[2])
    if not tox.INFO.IS_WIN:
        executable = sys.executable
        if use_builtin_venv(venv) and hasattr(sys, "real_prefix"):
            # workaround virtualenv prefixing issue w/ venv on python3
            executable = "python{}.{}".format(*sys.version_info)
            executable = os.path.join(sys.real_prefix, "bin", executable)
        # realpath is needed for stuff like the debian symlinks
        our_sys_path = py.path.local(executable).realpath()
        assert our_sys_path == py.path.local(args[0]).realpath()
        # assert Envconfig.toxworkdir in args
        assert venv.getcommandpath("easy_install", cwd=py.path.local())
    interp = venv._getliveconfig().base_resolved_python_path
    assert interp == venv.envconfig.python_info.executable
    assert venv.path_config.check(exists=False)
Exemple #2
0
def test_create(monkeypatch, mocksession, newconfig):
    config = newconfig([], """
        [testenv:py123]
    """)
    envconfig = config.envconfigs['py123']
    venv = VirtualEnv(envconfig, session=mocksession)
    assert venv.path == envconfig.envdir
    assert not venv.path.check()
    action = mocksession.newaction(venv, "getenv")
    tox_testenv_create(action=action, venv=venv)
    pcalls = mocksession._pcalls
    assert len(pcalls) >= 1
    args = pcalls[0].args
    module = 'venv' if use_builtin_venv(venv) else 'virtualenv'
    assert module == str(args[2])
    if sys.platform != "win32":
        executable = sys.executable
        if use_builtin_venv(venv) and hasattr(sys, 'real_prefix'):
            # workaround virtualenv prefixing issue w/ venv on python3
            _, executable = executable.rsplit('bin/', 1)
            executable = os.path.join(sys.real_prefix, 'bin/', executable)
        # realpath is needed for stuff like the debian symlinks
        assert py.path.local(executable).realpath() == py.path.local(args[0]).realpath()
        # assert Envconfig.toxworkdir in args
        assert venv.getcommandpath("easy_install", cwd=py.path.local())
    interp = venv._getliveconfig().python
    assert interp == venv.envconfig.python_info.executable
    assert venv.path_config.check(exists=False)
Exemple #3
0
 def test_python_recreation(self, tmpdir, newconfig, mocksession):
     pkg = tmpdir.ensure("package.tar.gz")
     config = newconfig([], "")
     envconfig = config.envconfigs['python']
     venv = VirtualEnv(envconfig, session=mocksession)
     cconfig = venv._getliveconfig()
     action = mocksession.newaction(venv, "update")
     venv.update(action)
     assert not venv.path_config.check()
     mocksession.installpkg(venv, pkg)
     assert venv.path_config.check()
     assert mocksession._pcalls
     args1 = map(str, mocksession._pcalls[0].args)
     module = 'venv' if use_builtin_venv(venv) else 'virtualenv'
     assert module in " ".join(args1)
     mocksession.report.expect("*", "*create*")
     # modify config and check that recreation happens
     mocksession._clearmocks()
     action = mocksession.newaction(venv, "update")
     venv.update(action)
     mocksession.report.expect("*", "*reusing*")
     mocksession._clearmocks()
     action = mocksession.newaction(venv, "update")
     cconfig.python = py.path.local("balla")
     cconfig.writeconfig(venv.path_config)
     venv.update(action)
     mocksession.report.expect("verbosity0", "*recreate*")
Exemple #4
0
 def test_python_recreation(self, tmpdir, newconfig, mocksession):
     pkg = tmpdir.ensure("package.tar.gz")
     config = newconfig(["-v"], "")
     mocksession.new_config(config)
     venv = mocksession.getvenv("python")
     create_config = venv._getliveconfig()
     with mocksession.newaction(venv.name, "update") as action:
         venv.update(action)
         assert not venv.path_config.check()
     installpkg(venv, pkg)
     assert venv.path_config.check()
     assert mocksession._pcalls
     args1 = map(str, mocksession._pcalls[0].args)
     module = "venv" if use_builtin_venv(venv) else "virtualenv"
     assert module in " ".join(args1)
     mocksession.report.expect("*", "*create*")
     # modify config and check that recreation happens
     mocksession._clearmocks()
     with mocksession.newaction(venv.name, "update") as action:
         venv.update(action)
         mocksession.report.expect("*", "*reusing*")
         mocksession._clearmocks()
     with mocksession.newaction(venv.name, "update") as action:
         create_config.base_resolved_python_path = py.path.local("balla")
         create_config.writeconfig(venv.path_config)
         venv.update(action)
         mocksession.report.expect("verbosity0", "*recreate*")
Exemple #5
0
def test_alwayscopy_default(initproj, cmd, mocksession):
    initproj("example123",
             filedefs={
                 'tox.ini':
                 """
            [testenv]
            commands={envpython} --version
    """
             })
    venv = mocksession.getenv('python')
    result = cmd("-vv")
    assert not result.ret

    if use_builtin_venv(venv):
        assert "venv --copies" not in result.out
    else:
        assert "virtualenv --always-copy" not in result.out
Exemple #6
0
def test_alwayscopy_default(initproj, cmd, mocksession):
    initproj(
        "example123",
        filedefs={
            "tox.ini":
            """
            [testenv]
            commands={envpython} --version
    """
        },
    )
    venv = mocksession.getvenv("python")
    result = cmd("-vv")
    result.assert_success()
    if use_builtin_venv(venv):
        assert "venv --copies" not in result.out
    else:
        assert "virtualenv --always-copy" not in result.out
Exemple #7
0
def test_create_download(mocksession, newconfig, download):
    config = newconfig(
        [],
        """\
        [testenv:env]
        {}
        """.format("download={}".format(download) if download else ""),
    )
    mocksession.new_config(config)
    venv = mocksession.getvenv("env")
    with mocksession.newaction(venv.name, "getenv") as action:
        tox_testenv_create(action=action, venv=venv)
    pcalls = mocksession._pcalls
    assert len(pcalls) >= 1
    args = pcalls[0].args
    # builtin venv does not support --no-download
    if download or use_builtin_venv(venv):
        assert "--no-download" not in map(str, args)
    else:
        assert "--no-download" in map(str, args)
    mocksession._clearmocks()