def test_venv_file(venv_name, PipenvInstance): """Tests virtualenv creation when a .venv file exists at the project root and contains a venv name. """ with PipenvInstance(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 if 'PIPENV_VENV_IN_PROJECT' in os.environ: del os.environ['PIPENV_VENV_IN_PROJECT'] c = p.pipenv('install') assert c.returncode == 0 c = p.pipenv('--venv') assert c.returncode == 0 venv_loc = Path(c.stdout.strip()).absolute() assert venv_loc.exists() assert venv_loc.joinpath('.project').exists() venv_path = normalize_drive(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).joinpath( venv_name).absolute().as_posix() assert venv_path == normalize_drive(venv_expected_path)
def test_venv_at_project_root(PipenvInstance): with temp_environ(): with PipenvInstance(chdir=True) as p: os.environ['PIPENV_VENV_IN_PROJECT'] = '1' c = p.pipenv('install') assert c.return_code == 0 assert normalize_drive(p.path) in p.pipenv('--venv').out del os.environ['PIPENV_VENV_IN_PROJECT'] os.mkdir('subdir') os.chdir('subdir') # should still detect installed assert normalize_drive(p.path) in p.pipenv('--venv').out
def test_venv_at_project_root(PipenvInstance): with temp_environ(): with PipenvInstance(chdir=True) as p: os.environ['PIPENV_VENV_IN_PROJECT'] = '1' c = p.pipenv('install') assert c.return_code == 0 assert normalize_drive(p.path) in p.pipenv('--venv').out del os.environ['PIPENV_VENV_IN_PROJECT'] os.mkdir('subdir') os.chdir('subdir') # should still detect installed assert normalize_drive(p.path) in p.pipenv('--venv').out
def test_venv_in_project(PipenvInstance, pypi): with temp_environ(): os.environ['PIPENV_VENV_IN_PROJECT'] = '1' with PipenvInstance(pypi=pypi) as p: c = p.pipenv('install requests') assert c.return_code == 0 assert normalize_drive(p.path) in p.pipenv('--venv').out
def test_reuse_previous_venv(self, pypi): with PipenvInstance(chdir=True, pypi=pypi) as p: os.mkdir('.venv') c = p.pipenv('install requests') assert c.return_code == 0 assert normalize_drive(p.path) in p.pipenv('--venv').out
def test_empty_venv_file(PipenvInstance): """Tests virtualenv creation when a empty .venv file exists at the project root """ with PipenvInstance(chdir=True) as p: file_path = os.path.join(p.path, '.venv') with open(file_path, 'w'): pass with temp_environ(), TemporaryDirectory( prefix='pipenv-', suffix='temp_workon_home') as workon_home: os.environ['WORKON_HOME'] = workon_home if 'PIPENV_VENV_IN_PROJECT' in os.environ: del os.environ['PIPENV_VENV_IN_PROJECT'] c = p.pipenv('install') assert c.returncode == 0 c = p.pipenv('--venv') assert c.returncode == 0 venv_loc = Path(c.stdout.strip()).absolute() assert venv_loc.exists() assert venv_loc.joinpath('.project').exists() from pathlib import PurePosixPath venv_path = normalize_drive(venv_loc.as_posix()) venv_path_parent = str(PurePosixPath(venv_path).parent) assert venv_path_parent == Path(workon_home).absolute().as_posix()
def test_venv_in_project(PipenvInstance, pypi): with temp_environ(): os.environ['PIPENV_VENV_IN_PROJECT'] = '1' with PipenvInstance(pypi=pypi) as p: c = p.pipenv('install requests') assert c.return_code == 0 assert normalize_drive(p.path) in p.pipenv('--venv').out
def test_shell_nested_venv_in_project(self, pypi): import subprocess with temp_environ(): os.environ['PIPENV_VENV_IN_PROJECT'] = '1' os.environ['PIPENV_IGNORE_VIRTUALENVS'] = '1' os.environ['PIPENV_SHELL_COMPAT'] = '1' with PipenvInstance(chdir=True, pypi=pypi) as p: # Signal to pew to look in the project directory for the environment os.environ['WORKON_HOME'] = p.path project = Project() c = p.pipenv('install requests') assert c.return_code == 0 assert 'requests' in p.pipfile['packages'] assert 'requests' in p.lockfile['default'] # Check that .venv now shows in pew's managed list pew_list = delegator.run('pewtwo ls') assert '.venv' in pew_list.out # Check for the venv directory c = delegator.run('pewtwo dir .venv') # Compare pew's virtualenv path to what we expect venv_path = get_windows_path(project.project_directory, '.venv') # os.path.normpath will normalize slashes assert venv_path == normalize_drive( os.path.normpath(c.out.strip())) # Have pew run 'pip freeze' in the virtualenv # This is functionally the same as spawning a subshell # If we can do this we can theoretically make a subshell # This test doesn't work on *nix if os.name == 'nt': args = ['pewtwo', 'in', '.venv', 'pip', 'freeze'] process = subprocess.Popen(args, shell=True, universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _ = process.communicate() assert any( req.startswith('requests') for req in out.splitlines()) is True
def test_pipenv_where(PipenvInstance, pypi_secure): with PipenvInstance(pypi=pypi_secure) as p: assert normalize_drive(p.path) in p.pipenv('--where').out
def test_pipenv_where(self): with PipenvInstance() as p: assert normalize_drive(p.path) in p.pipenv('--where').out
def test_pipenv_where(PipenvInstance): with PipenvInstance() as p: c = p.pipenv("--where") assert c.ok assert normalize_drive(p.path) in c.out
def test_pipenv_where(PipenvInstance): with PipenvInstance() as p: c = p.pipenv("--where") assert c.returncode == 0 assert normalize_drive(p.path) in c.stdout
def test_pipenv_where(PipenvInstance, pypi_secure): with PipenvInstance(pypi=pypi_secure) as p: assert normalize_drive(p.path) in p.pipenv('--where').out
def test_reuse_previous_venv(PipenvInstance, pypi): with PipenvInstance(chdir=True, pypi=pypi) as p: os.mkdir('.venv') c = p.pipenv('install requests') assert c.return_code == 0 assert normalize_drive(p.path) in p.pipenv('--venv').out