def mock_env_home(TempEnviron, mock_projects_dir, venv_fresh): __cwd = os.getcwd() with TemporaryDirectory(prefix='pipenv_home_real') as pipenv_home: project_names = os.listdir(mock_projects_dir) for project_name in project_names: project_dir = os.path.join(mock_projects_dir, project_name) pipfile = os.path.join(project_dir, 'Pipfile') touch(pipfile) os.chdir(project_dir) with TempEnviron(WORKON_HOME=pipenv_home): project = Project() envname = project.virtualenv_name os.chdir(__cwd) envpath = os.path.join(pipenv_home, envname) shutil.copytree(venv_fresh, envpath) # Make Project Links envs = find_environments(pipenv_home) for e in envs: project_dir = os.path.join(mock_projects_dir, e.project_name) write_project_dir_project_file(envpath=e.envpath, project_dir=project_dir) with TempEnviron(WORKON_HOME=pipenv_home): yield pipenv_home, mock_projects_dir os.chdir(__cwd)
def test_find_environments(self, mock_env_home): pipenv_home, mock_projects_dir = mock_env_home # Add a non env to mock projects ensure it's not picked up os.makedirs(os.path.join(pipenv_home, 'notanenv')) environments = find_environments(pipenv_home) assert len(environments) == 2 assert 'proj1' in [e.project_name for e in environments]
def test_find_environments_does_not_exit(self): """ Invalid Folder. CLI Entry should catch, core func should fail """ with pytest.raises(IOError): find_environments('/fakedir/')
def test_find_environments_empty(self, temp_folder): """ Environment could be empty """ environments = find_environments(temp_folder) assert len(environments) == 0