コード例 #1
0
ファイル: conftest.py プロジェクト: theasylum/pipenv
def local_tempdir(request):
    old_temp = os.environ.get("TEMP", "")
    new_temp = Path(os.getcwd()).absolute() / "temp"
    new_temp.mkdir(parents=True, exist_ok=True)
    os.environ["TEMP"] = new_temp.as_posix()

    def finalize():
        os.environ['TEMP'] = fs_str(old_temp)
        _rmtree_func(new_temp.as_posix())

    request.addfinalizer(finalize)
    with TemporaryDirectory(dir=new_temp.as_posix()) as temp_dir:
        yield Path(temp_dir.name)
コード例 #2
0
def test_venv_file(venv_name, PipenvInstance, pypi):
    """Tests virtualenv creation when a .venv file exists at the project root
    and contains a venv name.
    """
    with PipenvInstance(pypi=pypi, chdir=True) as p:
        file_path = os.path.join(p.path, '.venv')
        with open(file_path, 'w') as f:
            f.write(venv_name)

        with temp_environ(), TemporaryDirectory(
            prefix='pipenv-', suffix='temp_workon_home'
        ) as workon_home:
            os.environ['WORKON_HOME'] = workon_home.name
            if 'PIPENV_VENV_IN_PROJECT' in os.environ:
                del os.environ['PIPENV_VENV_IN_PROJECT']

            c = p.pipenv('install')
            assert c.return_code == 0

            c = p.pipenv('--venv')
            assert c.return_code == 0
            venv_loc = Path(c.out.strip()).absolute()
            assert venv_loc.exists()
            assert venv_loc.joinpath('.project').exists()
            venv_path = venv_loc.as_posix()
            if os.path.sep in venv_name:
                venv_expected_path = Path(p.path).joinpath(venv_name).absolute().as_posix()
            else:
                venv_expected_path = Path(workon_home.name).joinpath(venv_name).absolute().as_posix()
            assert venv_path == venv_expected_path