def test_create_pipfile(self): proj = pipenv.project.Project(which=pipenv.core.which) # Create test space. delegator.run('mkdir test_pipfile') with open('test_pipfile/pip.conf', 'w') as f: f.write('[install]\nextra-index-url = \n' ' https://pypi.host.com/simple\n' ' https://remote.packagehost.net/simple') os.chdir('test_pipfile') os.environ['PIP_CONFIG_FILE'] = 'pip.conf' proj.create_pipfile() proj._pipfile_location = 'Pipfile' pfile = proj.parsed_pipfile os.chdir('..') # Cleanup test space. delegator.run('rm -fr test_pipfile') # Confirm source added correctly. default_source = pfile['source'][0] assert default_source['url'] == 'https://pypi.python.org/simple' assert default_source['name'] == 'pypi' assert default_source['verify_ssl'] is True config_source_1 = pfile['source'][1] assert config_source_1['url'] == 'https://pypi.host.com/simple' assert config_source_1['name'] == 'pip_index_0' assert config_source_1['verify_ssl'] is True config_source_2 = pfile['source'][2] assert config_source_2[ 'url'] == 'https://remote.packagehost.net/simple' assert config_source_2['name'] == 'pip_index_1' assert config_source_2['verify_ssl'] is True
def test_remove_package_from_pipfile(self): proj = pipenv.project.Project() # Create test space. delegator.run('mkdir test_remove_from_pipfile') with open('test_remove_from_pipfile/Pipfile', 'w') as f: f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n' 'verify_ssl = true\n\n\n[packages]\n' 'requests = { extras = [\'socks\'] }\nFlask = \'*\'\n\n\n' '[dev-packages]\nclick = \'*\'\nDjango = \'*\'\n') proj._pipfile_location = 'test_remove_from_pipfile/Pipfile' # Confirm initial state of Pipfile. p = proj.parsed_pipfile assert list(p['packages'].keys()) == ['requests', 'Flask'] assert list(p['dev-packages'].keys()) == ['click', 'Django'] # Remove requests from packages and click from dev-packages. proj.remove_package_from_pipfile('requests') proj.remove_package_from_pipfile('click', dev=True) proj.remove_package_from_pipfile('DJANGO', dev=True) p = proj.parsed_pipfile # Cleanup test space. delegator.run('rm -fr test_remove_from_pipfile') # Confirm state of Pipfile. assert 'Flask' in p['packages'] assert len(p['packages']) == 1
def test_add_package_to_pipfile(self): proj = pipenv.project.Project() # Create test space. delegator.run('mkdir test_add_to_pipfile') with open('test_add_to_pipfile/Pipfile', 'w') as f: f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n' 'verify_ssl = true\n\n\n[packages]\n' 'requests = { extras = [\'socks\'] }') proj._pipfile_location = 'test_add_to_pipfile/Pipfile' proj.add_package_to_pipfile('Flask') proj.add_package_to_pipfile('Django==1.10.1', dev=True) proj.add_package_to_pipfile('Click-ComPletiON') p = proj.parsed_pipfile # Cleanup test space. delegator.run('rm -fr test_add_to_pipfile') # Confirm Flask added to packages. assert 'flask' in p['packages'] assert p['packages']['flask'] == '*' # Confirm Django added to dev-packages. assert 'django' in p['dev-packages'] assert p['dev-packages']['django'] == '==1.10.1' # Confirm casing is normalized. assert 'click-completion' in p['packages'] assert p['packages']['click-completion'] == '*'
def test_internal_lockfile(self): proj = pipenv.project.Project() # Create test space. delegator.run('mkdir test_internal_lockfile') with open('test_internal_lockfile/Pipfile', 'w') as f: f.write( '[[source]]\nurl = \'https://pypi.python.org/simple\'\n' 'verify_ssl = true\n\n\n[packages]\n' 'Requests = { extras = [\'socks\'] }\nFlask_Auth = \'*\'\n\n\n' '[dev-packages]\nclick = \'*\'\nDjango = {git = ' '"https://github.com/django/django.git", ref="1.10"}\n') proj._pipfile_location = 'test_internal_lockfile/Pipfile' lockfile = proj._lockfile # Verify default section of lockfile. assert len(lockfile['default'].keys()) == 2 assert 'requests' in lockfile['default'] assert 'flask-auth' in lockfile['default'] # Verify develop section of lockfile. assert lockfile['develop']['django'][ 'git'] == 'https://github.com/django/django.git' assert lockfile['develop']['click'] == '*' # Verify _meta exists. assert lockfile['_meta']['hash'] == { 'sha256': 'ff0b0584610a7091156f32ca7d5adab8f29cb17263c6d63bcab42de2137c4787' } delegator.run('rm -fr test_internal_lockfile')
def test_cli_usage(self): delegator.run('mkdir test_project') os.chdir('test_project') os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run('copy /y nul Pipfile').return_code == 0 assert delegator.run('pipenv install Werkzeug').return_code == 0 assert delegator.run('pipenv install pytest --dev').return_code == 0 assert delegator.run('pipenv install git+https://github.com/requests/[email protected]#egg=requests').return_code == 0 assert delegator.run('pipenv lock').return_code == 0 # Test uninstalling a package after locking. assert delegator.run('pipenv uninstall Werkzeug').return_code == 0 pipfile_output = delegator.run('type Pipfile').out lockfile_output = delegator.run('type Pipfile.lock').out # Ensure uninstall works. assert 'Werkzeug' not in pipfile_output assert 'werkzeug' not in lockfile_output # Ensure dev-packages work. assert 'pytest' in pipfile_output assert 'pytest' in lockfile_output # Ensure vcs dependencies work. assert 'requests' in pipfile_output assert '"git": "https://github.com/requests/requests.git"' in lockfile_output os.chdir('..') shutil.rmtree('test_project')
def test_pipenv_uninstall_dev(self): delegator.run('mkdir test_pipenv_uninstall_dev') os.chdir('test_pipenv_uninstall_dev') # Build the environment. os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run('touch Pipfile').return_code == 0 assert delegator.run('pipenv --python python').return_code == 0 # Add entries to Pipfile. assert delegator.run('pipenv install pytest --dev').return_code == 0 pipfile_output = delegator.run('cat Pipfile').out pipfile_list = pipfile_output.split('\n') assert '[dev-packages]' in pipfile_list assert 'pytest = "*"' in pipfile_list # Uninstall from dev-packages, removing TOML section. assert delegator.run('pipenv uninstall -d pytest').return_code == 0 pipfile_output = delegator.run('cat Pipfile').out pipfile_list = pipfile_output.split('\n') assert 'pytest = "*"' not in pipfile_list os.chdir('..') delegator.run('rm -fr test_pipenv_uninstall_dev')
def test_internal_lockfile(self): proj = pipenv.project.Project() # Create test space. delegator.run('mkdir test_internal_lockfile') with open('test_internal_lockfile/Pipfile', 'w') as f: f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n' 'verify_ssl = true\n\n\n[packages]\n' 'Requests = { extras = [\'socks\'] }\nFlask_Auth = \'*\'\n\n\n' '[dev-packages]\nclick = \'*\'\nDjango = {git = ' '"https://github.com/django/django.git", ref="1.10"}\n') proj._pipfile_location = 'test_internal_lockfile/Pipfile' lockfile = proj._lockfile # Verify default section of lockfile. assert len(lockfile['default'].keys()) == 2 assert 'requests' in lockfile['default'] assert 'flask-auth' in lockfile['default'] # Verify develop section of lockfile. assert lockfile['develop']['django']['git'] == 'https://github.com/django/django.git' assert lockfile['develop']['click'] == '*' # Verify _meta exists. assert lockfile['_meta']['hash'] == {'sha256': 'ff0b0584610a7091156f32ca7d5adab8f29cb17263c6d63bcab42de2137c4787'} delegator.run('rm -fr test_internal_lockfile')
def test_cli_with_custom_python_path(self): delegator.run('mkdir custom_python') os.chdir('custom_python') c = delegator.run('pipenv install --python={0}'.format(FULL_PYTHON_PATH)) # Debugging, if it fails. print(c.out) print(c.err) assert c.return_code == 0
def test_timeout_short(self): delegator.run('mkdir test_timeout_short') os.chdir('test_timeout_short') os.environ['PIPENV_VENV_IN_PROJECT'] = '1' os.environ['PIPENV_TIMEOUT'] = '0' assert delegator.run('copy /y nul Pipfile').return_code == 0 os.chdir('..') shutil.rmtree('test_timeout_short') del os.environ['PIPENV_TIMEOUT']
def test_multiple_editable_packages_should_not_race(PipenvInstance, testsroot): """Test for a race condition that can occur when installing multiple 'editable' packages at once, and which causes some of them to not be importable. This issue had been fixed for VCS packages already, but not local 'editable' packages. So this test locally installs packages from tarballs that have already been committed in the local `pypi` dir to avoid using VCS packages. """ pkgs = ["requests", "flask", "six", "jinja2"] pipfile_string = """ [dev-packages] [packages] """ with PipenvInstance(chdir=True) as p: for pkg_name in pkgs: source_path = p._pipfile.get_fixture_path("git/{0}/".format(pkg_name)).as_posix() c = delegator.run("git clone {0} ./{1}".format(source_path, pkg_name)) assert c.return_code == 0 pipfile_string += '"{0}" = {{path = "./{0}", editable = true}}\n'.format(pkg_name) with open(p.pipfile_path, 'w') as f: f.write(pipfile_string.strip()) c = p.pipenv('install') assert c.return_code == 0 c = p.pipenv('run python -c "import requests, flask, six, jinja2"') assert c.return_code == 0, c.err
def check_github_ssh(): res = False try: # `ssh -T [email protected]` will return successfully with return_code==1 # and message 'Hi <username>! You've successfully authenticated, but # GitHub does not provide shell access.' if ssh keys are available and # registered with GitHub. Otherwise, the command will fail with # return_code=255 and say 'Permission denied (publickey).' c = delegator.run('ssh -T [email protected]') res = True if c.return_code == 1 else False except KeyboardInterrupt: warnings.warn( "KeyboardInterrupt while checking GitHub ssh access", RuntimeWarning ) except Exception: pass global HAS_WARNED_GITHUB if not res and not HAS_WARNED_GITHUB: warnings.warn( 'Cannot connect to GitHub via SSH', RuntimeWarning ) warnings.warn( 'Will skip tests requiring SSH access to GitHub', RuntimeWarning ) HAS_WARNED_GITHUB = True return res
def pipenv(self, cmd, block=True): if self.pipfile_path and os.path.isfile(self.pipfile_path): os.environ['PIPENV_PIPFILE'] = fs_str(self.pipfile_path) # a bit of a hack to make sure the virtualenv is created with TemporaryDirectory(prefix='pipenv-', suffix='-cache') as tempdir: os.environ['PIPENV_CACHE_DIR'] = fs_str(tempdir.name) c = delegator.run('pipenv {0}'.format(cmd), block=block, cwd=os.path.abspath(self.path), env=os.environ.copy()) if 'PIPENV_CACHE_DIR' in os.environ: del os.environ['PIPENV_CACHE_DIR'] if 'PIPENV_PIPFILE' in os.environ: del os.environ['PIPENV_PIPFILE'] # Pretty output for failing tests. if block: print('$ pipenv {0}'.format(cmd)) print(c.out) print(c.err, file=sys.stderr) if c.return_code != 0: print("Command failed...") # Where the action happens. return c
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_internal_pipfile(self): proj = pipenv.project.Project() # Create test space. delegator.run('mkdir test_internal_pipfile') with open('test_internal_pipfile/Pipfile', 'w') as f: f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n' 'verify_ssl = true\n\n\n[packages]\n' 'requests = { extras = [\'socks\'] }\nFlask_Auth = \'*\'\n\n\n' '[dev-packages]\nclick = \'*\'\nDjango = {git = ' '"https://github.com/django/django.git", ref="1.10"}\n') proj._pipfile_location = 'test_internal_pipfile/Pipfile' p = proj._pipfile # Test package names are normalized as expected. assert list(p['packages'].keys()) == ['requests', 'flask-auth'] assert list(p['dev-packages'].keys()) == ['click', 'django'] delegator.run('rm -fr test_internal_pipfile')
def test_lock_requirements_file(self): delegator.run('mkdir test_pipenv_requirements') os.chdir('test_pipenv_requirements') pip_str = ("[packages]\n" "requests = \"==2.14.0\"\n" "flask = \"==0.12.2\"\n\n" "[dev-packages]\n" "pytest = \"==3.1.1\"\n") req_list = ("requests==2.14.0", "flask==0.12.2", "pytest==3.1.1") # Build the environment. os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run( 'echo \'{0}\' > Pipfile'.format(pip_str)).return_code == 0 # Validate requirements.txt. c = delegator.run('pipenv lock -r') assert c.return_code == 0 for req in req_list: assert req in c.out # Cleanup. os.chdir('..') delegator.run('rm -fr test_pipenv_requirements')
def test_shell_nested_venv_in_project(self): 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) 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('pew ls') assert '.venv' in pew_list.out # Check for the venv directory c = delegator.run('pew 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 == 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 amke a subshell # This test doesn't work on *nix if os.name == 'nt': args = ['pew', '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_uninstall(self): delegator.run('mkdir test_pipenv_uninstall') os.chdir('test_pipenv_uninstall') # Build the environment. os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run('copy /y nul Pipfile').return_code == 0 assert delegator.run('pipenv install').return_code == 0 # Add entries to Pipfile. assert delegator.run('pipenv install Werkzeug').return_code == 0 assert delegator.run('pipenv install pytest --dev').return_code == 0 pipfile_output = delegator.run('type Pipfile').out pipfile_list = pipfile_output.split('\n') assert 'werkzeug = "*"' in pipfile_list assert 'pytest = "*"' in pipfile_list assert '[packages]' in pipfile_list assert '[dev-packages]' in pipfile_list # Uninstall from dev-packages, removing TOML section. assert delegator.run('pipenv uninstall pytest').return_code == 0 # Test uninstalling non-existant dependency. c = delegator.run('pipenv uninstall NotAPackage') assert c.return_code == 0 assert 'No package NotAPackage to remove from Pipfile.' in c.out pipfile_output = delegator.run('type Pipfile').out pipfile_list = pipfile_output.split('\n') assert 'Werkzeug = "*"' in pipfile_list assert 'pytest = "*"' not in pipfile_list assert '[packages]' in pipfile_list # assert '[dev-packages]' not in pipfile_list os.chdir('..') shutil.rmtree('test_pipenv_uninstall')
def test_parsed_pipfile(self): proj = pipenv.project.Project() # Create test space. delegator.run('mkdir test_pipfile') with open('test_pipfile/Pipfile', 'w') as f: f.write('[[source]]\nurl = \'https://pypi.python.org/simple\'\n' 'verify_ssl = true\n\n\n[packages]\n' 'requests = { extras = [\'socks\'] }') proj._pipfile_location = 'test_pipfile/Pipfile' pfile = proj.parsed_pipfile # Cleanup test space. delegator.run('rm -fr test_pipfile') # Confirm source added correctly. assert 'source' in pfile assert pfile['source'][0]['url'] == 'https://pypi.python.org/simple' # Confirm requests is in packages as expected. assert 'packages' in pfile assert 'socks' in pfile['packages']['requests']['extras']
def virtualenv(pathlib_tmpdir): virtualenv_path = pathlib_tmpdir / "venv" with temp_environ(): c = delegator.run("virtualenv {}".format(virtualenv_path), block=True) assert c.return_code == 0 for name in ("bin", "Scripts"): activate_this = virtualenv_path / name / "activate_this.py" if activate_this.exists(): with open(str(activate_this)) as f: code = compile(f.read(), str(activate_this), "exec") exec(code, dict(__file__=str(activate_this))) break else: raise VirtualenvActivationException("Can't find the activate_this.py script.") os.environ["VIRTUAL_ENV"] = str(virtualenv_path) yield virtualenv_path
def test_requirements_to_pipfile(self): delegator.run('mkdir test_requirements_to_pip') os.chdir('test_requirements_to_pip') os.environ['PIPENV_VENV_IN_PROJECT'] = '1' os.environ['PIPENV_MAX_DEPTH'] = '1' with open('requirements.txt', 'w') as f: f.write( 'requests[socks]==2.18.1\n' 'git+https://github.com/kennethreitz/[email protected]#egg=records\n' '-e git+https://github.com/kennethreitz/[email protected]#egg=tablib\n' 'six==1.10.0\n') assert delegator.run('pipenv --python python').return_code == 0 print(delegator.run('pipenv lock').err) assert delegator.run('pipenv lock').return_code == 0 pipfile_output = delegator.run('cat Pipfile').out lockfile_output = delegator.run('cat Pipfile.lock').out # Ensure extras work. assert 'socks' in pipfile_output assert 'pysocks' in lockfile_output # Ensure vcs dependencies work. assert 'records' in pipfile_output assert '"git": "https://github.com/kennethreitz/records.git"' in lockfile_output # Ensure editable packages work. assert 'ref = "v0.11.5"' in pipfile_output assert '"editable": true' in lockfile_output # Ensure BAD_PACKAGES aren't copied into Pipfile from requirements.txt. assert 'six = "==1.10.0"' not in pipfile_output os.chdir('..') delegator.run('rm -fr test_requirements_to_pip') del os.environ['PIPENV_MAX_DEPTH']
def pipenv(self, cmd, block=True): if self.pipfile_path: os.environ['PIPENV_PIPFILE'] = self.pipfile_path c = delegator.run('pipenv {0}'.format(cmd), block=block) if 'PIPENV_PIPFILE' in os.environ: del os.environ['PIPENV_PIPFILE'] # Pretty output for failing tests. if block: print('$ pipenv {0}'.format(cmd)) print(c.out) print(c.err) # Where the action happens. return c
def test_system_and_deploy_work(PipenvInstance): with PipenvInstance(chdir=True) as p: c = p.pipenv("install tablib") assert c.return_code == 0 c = p.pipenv("--rm") assert c.return_code == 0 c = delegator.run("virtualenv .venv") assert c.return_code == 0 c = p.pipenv("install --system --deploy") assert c.return_code == 0 c = p.pipenv("--rm") assert c.return_code == 0 Path(p.pipfile_path).write_text(u""" [packages] tablib = "*" """.strip()) c = p.pipenv("install --system") assert c.return_code == 0
def test_system_and_deploy_work(PipenvInstance, pypi): with PipenvInstance(chdir=True, pypi=pypi) as p: c = p.pipenv('install six requests') assert c.return_code == 0 c = p.pipenv('--rm') assert c.return_code == 0 c = delegator.run('virtualenv .venv') assert c.return_code == 0 c = p.pipenv('install --system --deploy') assert c.return_code == 0 c = p.pipenv('--rm') assert c.return_code == 0 Path(p.pipfile_path).write_text(u""" [packages] requests """.strip()) c = p.pipenv('install --system') assert c.return_code == 0
def test_pipenv_run(self): working_dir = 'test_pipenv_run' delegator.run('mkdir {0}'.format(working_dir)) os.chdir(working_dir) # Build the environment. os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run('copy /y nul Pipfile').return_code == 0 # Install packages for test. assert delegator.run('pipenv install pep8').return_code == 0 assert delegator.run('pipenv install pytest').return_code == 0 # Run test commands. assert delegator.run('pipenv run python -c \'print("test")\'').return_code == 0 assert delegator.run('pipenv run pep8 --version').return_code == 0 assert delegator.run('pipenv run pytest --version').return_code == 0 os.chdir('..') shutil.rmtree(working_dir)
def test_timeout_short(self): delegator.run('mkdir test_timeout_short') os.chdir('test_timeout_short') os.environ['PIPENV_VENV_IN_PROJECT'] = '1' os.environ['PIPENV_TIMEOUT'] = '1' assert delegator.run('touch Pipfile').return_code == 0 assert delegator.run('pipenv --python python').return_code == 1 os.chdir('..') delegator.run('rm -fr test_timeout_short') del os.environ['PIPENV_TIMEOUT']
def test_system_and_deploy_work(PipenvInstance, pypi): with PipenvInstance(chdir=True, pypi=pypi) as p: c = p.pipenv("install six requests") assert c.return_code == 0 c = p.pipenv("--rm") assert c.return_code == 0 c = delegator.run("virtualenv .venv") assert c.return_code == 0 c = p.pipenv("install --system --deploy") assert c.return_code == 0 c = p.pipenv("--rm") assert c.return_code == 0 Path(p.pipfile_path).write_text( u""" [packages] requests """.strip() ) c = p.pipenv("install --system") assert c.return_code == 0
def pipenv(self, cmd, block=True): if self.pipfile_path: os.environ['PIPENV_PIPFILE'] = self.pipfile_path with TemporaryDirectory(prefix='pipenv-', suffix='-cache') as tempdir: os.environ['PIPENV_CACHE_DIR'] = tempdir.name c = delegator.run('pipenv {0}'.format(cmd), block=block) if 'PIPENV_CACHE_DIR' in os.environ: del os.environ['PIPENV_CACHE_DIR'] if 'PIPENV_PIPFILE' in os.environ: del os.environ['PIPENV_PIPFILE'] # Pretty output for failing tests. if block: print('$ pipenv {0}'.format(cmd)) print(c.out) print(c.err) # Where the action happens. return c
def test_lock_requirements_file(self): delegator.run('mkdir test_pipenv_requirements') os.chdir('test_pipenv_requirements') os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run('copy /y nul Pipfile').return_code == 0 assert delegator.run('pipenv install requests==2.14.0').return_code == 0 assert delegator.run('pipenv install flask==0.12.2').return_code == 0 assert delegator.run('pipenv install --dev pytest==3.1.1').return_code == 0 req_list = ("requests==2.14.0", "flask==0.12.2", "pytest==3.1.1") # Validate requirements.txt. c = delegator.run('pipenv lock -r') assert c.return_code == 0 for req in req_list: assert req in c.out # Cleanup. os.chdir('..') shutil.rmtree('test_pipenv_requirements')
def handle_venv_symlink(): if PYENV_INSTALLED and workon and venv_name: src = os.path.join(workon, venv_name) dst = os.path.join(PYENV_ROOT, "versions", venv_name) # delete broken links, which might be caused by actions such as --rm if os.path.islink(dst) and not os.path.exists(dst): os.unlink(dst) # perhaps we can link with another pre-existing virtual environment versions = delegator.run("pyenv versions").out.splitlines( keepends=False) for v in versions: v = v.split() v = v[0] if v[0] != "*" else v[1] if "/envs/" in v: if v.endswith(venv_name): src = os.path.join(PYENV_ROOT, "versions", v) break # create a symlink between source and destination if os.path.exists(src) and not os.path.exists(dst): os.symlink(src, dst)
def test_requirements_to_pipfile(PipenvInstance, pypi): with PipenvInstance(pipfile=False, chdir=True, pypi=pypi) as p: # Write a requirements file with open("requirements.txt", "w") as f: f.write("requests[socks]==2.18.1\n") c = p.pipenv("install") assert c.return_code == 0 print(c.out) print(c.err) print(delegator.run("ls -l").out) # assert stuff in pipfile assert "requests" in p.pipfile["packages"] assert "extras" in p.pipfile["packages"]["requests"] # assert stuff in lockfile assert "requests" in p.lockfile["default"] assert "chardet" in p.lockfile["default"] assert "idna" in p.lockfile["default"] assert "urllib3" in p.lockfile["default"] assert "pysocks" in p.lockfile["default"]
def test_requirements_to_pipfile(self): with PipenvInstance(pipfile=False, chdir=True) as p: # Write a requirements file with open('requirements.txt', 'w') as f: f.write('requests[socks]==2.18.1\n') c = p.pipenv('install') assert c.return_code == 0 print(c.out) print(c.err) print(delegator.run('ls -l').out) # assert stuff in pipfile assert 'requests' in p.pipfile['packages'] assert 'extras' in p.pipfile['packages']['requests'] # assert stuff in lockfile assert 'requests' in p.lockfile['default'] assert 'chardet' in p.lockfile['default'] assert 'idna' in p.lockfile['default'] assert 'urllib3' in p.lockfile['default'] assert 'pysocks' in p.lockfile['default']
def test_proper_names_unamanged_virtualenv(PipenvInstance, pypi): with PipenvInstance(chdir=True, pypi=pypi): c = delegator.run('python -m virtualenv .venv') assert c.return_code == 0 project = Project() assert project.proper_names == []
def test_cli_usage(self): delegator.run('mkdir test_project') os.chdir('test_project') os.environ['PIPENV_VENV_IN_PROJECT'] = '1' assert delegator.run('touch Pipfile').return_code == 0 assert delegator.run('pipenv --python python').return_code == 0 assert delegator.run('pipenv install Werkzeug').return_code == 0 assert delegator.run('pipenv install pytest --dev').return_code == 0 # assert delegator.run('pipenv install https://pypi.python.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl#md5=eb9be71cc41fd73a51a7c9cd1adde5de').return_code == 0 # Debug. print(delegator.run('pipenv install regex').err) assert delegator.run( 'pipenv install regex').return_code == 0 # failing before assert delegator.run( 'pipenv install git+https://github.com/requests/[email protected]#egg=requests' ).return_code == 0 assert delegator.run('pipenv lock').return_code == 0 # Test uninstalling a package after locking. assert delegator.run('pipenv uninstall Werkzeug').return_code == 0 pipfile_output = delegator.run('cat Pipfile').out lockfile_output = delegator.run('cat Pipfile.lock').out # Ensure uninstall works. assert 'Werkzeug' not in pipfile_output assert 'werkzeug' not in lockfile_output # Ensure dev-packages work. assert 'pytest' in pipfile_output assert 'pytest' in lockfile_output # Ensure vcs dependencies work. assert 'requests' in pipfile_output assert '"git": "https://github.com/requests/requests.git"' in lockfile_output os.chdir('..') delegator.run('rm -fr test_project')