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
def test_install_venv_project_directory(PipenvInstance): """Test the project functionality during virtualenv creation. """ with PipenvInstance(chdir=True) as p: 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 six") assert c.return_code == 0 venv_loc = None for line in c.err.splitlines(): if line.startswith("Virtualenv location:"): venv_loc = Path(line.split(":", 1)[-1].strip()) assert venv_loc is not None assert venv_loc.joinpath(".project").exists()
def test_install_venv_project_directory(PipenvInstance, pypi): """Test the project functionality during virtualenv creation. """ with PipenvInstance(pypi=pypi, chdir=True) as p: 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 six") assert c.return_code == 0 venv_loc = None for line in c.err.splitlines(): if line.startswith("Virtualenv location:"): venv_loc = Path(line.split(":", 1)[-1].strip()) assert venv_loc is not None assert venv_loc.joinpath(".project").exists()
def test_venv_file_with_path(PipenvInstance): """Tests virtualenv creation when a .venv file exists at the project root and contains an absolute path. """ with temp_environ(), PipenvInstance(chdir=True) as p: with TemporaryDirectory(prefix='pipenv-', suffix='-test_venv') as venv_path: if 'PIPENV_VENV_IN_PROJECT' in os.environ: del os.environ['PIPENV_VENV_IN_PROJECT'] file_path = os.path.join(p.path, '.venv') with open(file_path, 'w') as f: f.write(venv_path.name) c = p.pipenv('install') assert c.return_code == 0 c = p.pipenv('--venv') assert c.return_code == 0 venv_loc = Path(c.out.strip()) assert venv_loc.joinpath('.project').exists() assert venv_loc == Path(venv_path.name)
def test_venv_file_exists(PipenvInstance, pypi): """Tests virtualenv creation & package installation when a .venv file exists at the project root. """ 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('') 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 requests') assert c.return_code == 0 venv_loc = None for line in c.err.splitlines(): if line.startswith('Virtualenv location:'): venv_loc = Path(line.split(':', 1)[-1].strip()) assert venv_loc is not None assert venv_loc.joinpath('.project').exists()