def test_upgrade_vcs_req_with_no_dists_found(): """It can upgrade a VCS requirement that has no distributions otherwise.""" reset_env() req = "%s#egg=pip-test-package" % local_checkout("git+http://github.com/pypa/pip-test-package.git") run_pip("install", req) result = run_pip("install", "-U", req) assert not result.returncode
def test_install_with_pax_header(): """ test installing from a tarball with pax header for python<2.6 """ reset_env() run_from = abspath(join(tests_data, 'packages')) run_pip('install', 'paxpkg.tar.bz2', cwd=run_from)
def test_download_should_skip_existing_files(): """ It should not download files already existing in the scratch dir """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages/ 'initools' not in result.files_created # adding second package to test-req.txt write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 python-openid==2.2.5 """)) # only the second package should be downloaded result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) openid_tarball_prefix = str(Path('scratch')/ 'python-openid-') assert any(path.startswith(openid_tarball_prefix) for path in result.files_created) assert Path('scratch')/ 'INITools-0.1.tar.gz' not in result.files_created assert env.site_packages/ 'initools' not in result.files_created assert env.site_packages/ 'openid' not in result.files_created
def _test_config_file_override_stack(config_file): environ = clear_environ(os.environ.copy()) environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it reset_env(environ) write_file( config_file, textwrap.dedent("""\ [global] index-url = http://download.zope.org/ppix """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout reset_env(environ) write_file( config_file, textwrap.dedent("""\ [global] index-url = http://download.zope.org/ppix [install] index-url = http://pypi.appspot.com/ """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Getting page http://pypi.appspot.com/INITools" in result.stdout result = run_pip('install', '-vvv', '--index-url', 'http://pypi.python.org/simple', 'INITools', expect_error=True) assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
def test_create_bundle(): """ Test making a bundle. We'll grab one package from the filesystem (the FSPkg dummy package), one from vcs (initools) and one from an index (pip itself). """ env = reset_env() fspkg = path_to_url2(Path(tests_data) / 'packages' / 'FSPkg') run_pip('install', '-e', fspkg) pkg_lines = textwrap.dedent( '''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) # Create a bundle in env.scratch_path/ test.pybundle result = run_pip('bundle', '-r', env.scratch_path / 'bundle-req.txt', env.scratch_path / 'test.pybundle') bundle = result.files_after.get(join('scratch', 'test.pybundle'), None) assert bundle is not None files = zipfile.ZipFile(bundle.full).namelist() assert 'src/FSPkg/' in files assert 'src/initools/' in files assert 'build/pip/' in files
def test_check_submodule_addition(): """ Submodules are pulled in on install and updated on upgrade. """ # TODO(pnasrat) fix all helpers to do right things with paths on windows. if sys.platform == 'win32': raise SkipTest() env = reset_env() module_path, submodule_path = _create_test_package_with_submodule(env) install_result = run_pip('install', '-e', 'git+' + module_path + '#egg=version_pkg') assert '.virtualenv/src/version-pkg/testpkg/static/testfile' in install_result.files_created _change_test_package_submodule(env, submodule_path) _pull_in_submodule_changes_to_module(env, module_path) # expect error because git may write to stderr update_result = run_pip('install', '-e', 'git+' + module_path + '#egg=version_pkg', '--upgrade', expect_error=True) assert env.venv / 'src/version-pkg/testpkg/static/testfile2' in update_result.files_created
def test_install_user_conflict_in_globalsite(self): """ Test user install with conflict in global site ignores site and installs to usersite """ # the test framework only supports testing using virtualenvs # the sys.path ordering for virtualenvs with --system-site-packages is this: virtualenv-site, user-site, global-site # this test will use 2 modifications to simulate the user-site/global-site relationship # 1) a monkey patch which will make it appear INITools==0.2 is not in in the virtualenv site # if we don't patch this, pip will return an installation error: "Will not install to the usersite because it will lack sys.path precedence..." # 2) adding usersite to PYTHONPATH, so usersite as sys.path precedence over the virtualenv site env = reset_env(system_site_packages=True, sitecustomize=patch_dist_in_site_packages) env.environ["PYTHONPATH"] = env.root_path / env.user_site result1 = run_pip('install', 'INITools==0.2') result2 = run_pip('install', '--user', 'INITools==0.1') #usersite has 0.1 egg_info_folder = env.user_site / 'INITools-0.1-py%s.egg-info' % pyversion initools_folder = env.user_site / 'initools' assert egg_info_folder in result2.files_created, str(result2) assert initools_folder in result2.files_created, str(result2) #site still has 0.2 (can't look in result1; have to check) egg_info_folder = env.root_path / env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion initools_folder = env.root_path / env.site_packages / 'initools' assert isdir(egg_info_folder) assert isdir(initools_folder)
def test_freeze_with_requirement_option(): """ Test that new requirements are created correctly with --requirement hints """ reset_env() ignores = textwrap.dedent("""\ # Unchanged requirements below this line -r ignore.txt --requirement ignore.txt -Z ignore --always-unzip ignore -f http://ignore -i http://ignore --extra-index-url http://ignore --find-links http://ignore --index-url http://ignore """) write_file('hint.txt', textwrap.dedent("""\ INITools==0.1 NoExist==4.2 """) + ignores) result = run_pip('install', 'initools==0.2') result = pip_install_local('simple') result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True) expected = textwrap.dedent("""\ Script result: pip freeze --requirement hint.txt -- stderr: -------------------- Requirement file contains NoExist==4.2, but that package is not installed -- stdout: -------------------- INITools==0.2 """) + ignores + "## The following requirements were added by pip --freeze:..." _check_output(result, expected)
def test_uninstall_from_reqs_file(): """ Test uninstall from a requirements file. """ env = reset_env() write_file( 'test-req.txt', textwrap.dedent("""\ -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result = run_pip('install', '-r', 'test-req.txt') write_file( 'test-req.txt', textwrap.dedent("""\ # -f, -i, and --extra-index-url should all be ignored by uninstall -f http://www.example.com -i http://www.example.com --extra-index-url http://www.example.com -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y') assert_all_changes( result, result2, [env.venv / 'build', env.venv / 'src', env.scratch / 'test-req.txt'])
def test_freeze_mercurial_clone(): """ Test freezing a Mercurial clone. """ reset_env() env = get_env() result = env.run('hg', 'clone', '-r', 'c9963c111e7c', local_repo('hg+http://bitbucket.org/pypa/pip-test-package'), 'pip-test-package') result = env.run('python', 'setup.py', 'develop', cwd=env.scratch_path/'pip-test-package', expect_stderr=True) result = run_pip('freeze', expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze -- stdout: -------------------- ...-e %s@...#egg=pip_test_package-... ...""" % local_checkout('hg+http://bitbucket.org/pypa/pip-test-package')) _check_output(result, expected) result = run_pip('freeze', '-f', '%s#egg=pip_test_package' % local_checkout('hg+http://bitbucket.org/pypa/pip-test-package'), expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze -f %(repo)s#egg=pip_test_package -- stdout: -------------------- -f %(repo)s#egg=pip_test_package ...-e %(repo)s@...#egg=pip_test_package-dev ...""" % {'repo': local_checkout('hg+http://bitbucket.org/pypa/pip-test-package')}) _check_output(result, expected)
def test_freeze_bazaar_clone(): """ Test freezing a Bazaar clone. """ checkout_path = local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1') #bzr internally stores windows drives as uppercase; we'll match that. checkout_pathC = checkout_path.replace('c:', 'C:') reset_env() env = get_env() result = env.run('bzr', 'checkout', '-r', '174', local_repo('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'), 'django-wikiapp') result = env.run('python', 'setup.py', 'develop', cwd=env.scratch_path/'django-wikiapp') result = run_pip('freeze', expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze -- stdout: -------------------- ...-e %s@...#egg=django_wikiapp-... ...""" % checkout_pathC) _check_output(result, expected) result = run_pip('freeze', '-f', '%s/#egg=django-wikiapp' % checkout_path, expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp -- stdout: -------------------- -f %(repo)s/#egg=django-wikiapp ...-e %(repoC)s@...#egg=django_wikiapp-... ...""" % {'repoC': checkout_pathC, 'repo': checkout_path}) _check_output(result, expected)
def test_cleanup_after_create_bundle(): """ Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/. """ env = reset_env() # Install an editable to create a src/ dir. args = ['install'] args.extend(['-e', '%s#egg=pip-test-package' % local_checkout('git+http://github.com/pypa/pip-test-package.git')]) run_pip(*args) build = env.venv_path/"build" src = env.venv_path/"src" assert not exists(build), "build/ dir still exists: %s" % build assert exists(src), "expected src/ dir doesn't exist: %s" % src # Make the bundle. fspkg = 'file://%s/FSPkg' %join(tests_data, 'packages') pkg_lines = textwrap.dedent('''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) run_pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle') build_bundle = env.scratch_path/"build-bundle" src_bundle = env.scratch_path/"src-bundle" assert not exists(build_bundle), "build-bundle/ dir still exists: %s" % build_bundle assert not exists(src_bundle), "src-bundle/ dir still exists: %s" % src_bundle env.assert_no_temp() # Make sure previously created src/ from editable still exists assert exists(src), "expected src dir doesn't exist: %s" % src
def test_freeze_with_local_option(): """ Test that wsgiref (from global site-packages) is reported normally, but not with --local. """ reset_env() result = run_pip('install', 'initools==0.2') result = run_pip('freeze', expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze -- stdout: -------------------- INITools==0.2 wsgiref==... <BLANKLINE>""") # The following check is broken (see # http://bitbucket.org/ianb/pip/issue/110). For now we are simply # neutering this test, but if we can't find a way to fix it, # this whole function should be removed. # _check_output(result, expected) result = run_pip('freeze', '--local', expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze --local -- stdout: -------------------- INITools==0.2 <BLANKLINE>""") _check_output(result, expected)
def test_editable_no_install_followed_by_no_download(): """ Test installing an editable in two steps (first with --no-install, then with --no-download). """ reset_env() result = run_pip( 'install', '-e', '%s#egg=initools-dev' % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'), '--no-install', expect_error=True) result.assert_installed('INITools', without_egg_link=True, with_files=['.svn']) result = run_pip( 'install', '-e', '%s#egg=initools-dev' % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'), '--no-download', expect_error=True) result.assert_installed('INITools', without_files=[curdir, '.svn'])
def test_freeze_git_clone(): """ Test freezing a Git clone. """ env = reset_env() result = env.run('git', 'clone', local_repo('git+http://github.com/pypa/pip-test-package.git'), 'pip-test-package') result = env.run('git', 'checkout', '7d654e66c8fa7149c165ddeffa5b56bc06619458', cwd=env.scratch_path / 'pip-test-package', expect_stderr=True) result = env.run('python', 'setup.py', 'develop', cwd=env.scratch_path / 'pip-test-package') result = run_pip('freeze', expect_stderr=True) expected = textwrap.dedent("""\ Script result: ...pip freeze -- stdout: -------------------- ...-e %s@...#egg=pip_test_package-... ...""" % local_checkout('git+http://github.com/pypa/pip-test-package.git')) _check_output(result, expected) result = run_pip('freeze', '-f', '%s#egg=pip_test_package' % local_checkout('git+http://github.com/pypa/pip-test-package.git'), expect_stderr=True) expected = textwrap.dedent("""\ Script result: pip freeze -f %(repo)s#egg=pip_test_package -- stdout: -------------------- -f %(repo)s#egg=pip_test_package... -e %(repo)s@...#egg=pip_test_package-0.1.1 ...""" % {'repo': local_checkout('git+http://github.com/pypa/pip-test-package.git')}) _check_output(result, expected)
def test_upgrade_from_reqs_file(): """ Upgrade from a requirements file. """ env = reset_env() write_file( "test-req.txt", textwrap.dedent( """\ PyLogo<0.4 # and something else to test out: INITools==0.3 """ ), ) install_result = run_pip("install", "-r", env.scratch_path / "test-req.txt") write_file( "test-req.txt", textwrap.dedent( """\ PyLogo # and something else to test out: INITools """ ), ) run_pip("install", "--upgrade", "-r", env.scratch_path / "test-req.txt") uninstall_result = run_pip("uninstall", "-r", env.scratch_path / "test-req.txt", "-y") assert_all_changes(install_result, uninstall_result, [env.venv / "build", "cache", env.scratch / "test-req.txt"])
def test_no_install_followed_by_no_download(): """ Test installing in two steps (first with --no-install, then with --no-download). """ env = reset_env() egg_info_folder = env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion initools_folder = env.site_packages / 'initools' build_dir = env.venv / 'build' / 'INITools' result1 = run_pip('install', 'INITools==0.2', '--no-install', expect_error=True) assert egg_info_folder not in result1.files_created, str(result1) assert initools_folder not in result1.files_created, sorted( result1.files_created) assert build_dir in result1.files_created, result1.files_created assert build_dir / 'INITools.egg-info' in result1.files_created result2 = run_pip('install', 'INITools==0.2', '--no-download', expect_error=True) assert egg_info_folder in result2.files_created, str(result2) assert initools_folder in result2.files_created, sorted( result2.files_created) assert build_dir not in result2.files_created assert build_dir / 'INITools.egg-info' not in result2.files_created
def test_upgrade_from_reqs_file(): """ Upgrade from a requirements file. """ env = reset_env() write_file( 'test-req.txt', textwrap.dedent("""\ PyLogo<0.4 # and something else to test out: INITools==0.3 """)) install_result = run_pip('install', '-r', env.scratch_path / 'test-req.txt') write_file( 'test-req.txt', textwrap.dedent("""\ PyLogo # and something else to test out: INITools """)) run_pip('install', '--upgrade', '-r', env.scratch_path / 'test-req.txt') uninstall_result = run_pip('uninstall', '-r', env.scratch_path / 'test-req.txt', '-y') assert_all_changes( install_result, uninstall_result, [env.venv / 'build', 'cache', env.scratch / 'test-req.txt'])
def test_uninstall_overlapping_package(): """ Uninstalling a distribution that adds modules to a pre-existing package should only remove those added modules, not the rest of the existing package. See: GitHub issue #355 (pip uninstall removes things it didn't install) """ parent_pkg = abspath(join(tests_data, 'packages', 'parent-0.1.tar.gz')) child_pkg = abspath(join(tests_data, 'packages', 'child-0.1.tar.gz')) env = reset_env() result1 = run_pip('install', parent_pkg, expect_error=False) assert join(env.site_packages, 'parent') in result1.files_created, sorted(result1.files_created.keys()) result2 = run_pip('install', child_pkg, expect_error=False) assert join(env.site_packages, 'child') in result2.files_created, sorted(result2.files_created.keys()) assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result2.files_created, sorted(result2.files_created.keys()) #the import forces the generation of __pycache__ if the version of python supports it env.run('python', '-c', "import parent.plugins.child_plugin, child") result3 = run_pip('uninstall', '-y', 'child', expect_error=False) assert join(env.site_packages, 'child') in result3.files_deleted, sorted(result3.files_created.keys()) assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result3.files_deleted, sorted(result3.files_deleted.keys()) assert join(env.site_packages, 'parent') not in result3.files_deleted, sorted(result3.files_deleted.keys()) # Additional check: uninstalling 'child' should return things to the # previous state, without unintended side effects. assert_all_changes(result2, result3, [])
def test_uninstall_from_reqs_file(): """ Test uninstall from a requirements file. """ env = reset_env() write_file('test-req.txt', textwrap.dedent("""\ -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result = run_pip('install', '-r', 'test-req.txt') write_file('test-req.txt', textwrap.dedent("""\ # -f, -i, and --extra-index-url should all be ignored by uninstall -f http://www.example.com -i http://www.example.com --extra-index-url http://www.example.com -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y') assert_all_changes( result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
def _test_uninstall_editable_with_source_outside_venv(tmpdir): env = reset_env() result = env.run('git', 'clone', local_repo('git+git://github.com/pypa/virtualenv'), tmpdir) result2 = run_pip('install', '-e', tmpdir) assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), list(result2.files_created.keys()) result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True) assert_all_changes(result, result3, [env.venv/'build'])
def test_upgrade_vcs_req_with_dist_found(): """It can upgrade a VCS requirement that has distributions on the index.""" reset_env() # TODO(pnasrat) Using local_checkout fails on windows - oddness with the test path urls/git. req = "%s#egg=virtualenv" % "git+git://github.com/pypa/virtualenv@c21fef2c2d53cf19f49bcc37f9c058a33fb50499" run_pip("install", req) result = run_pip("install", "-U", req) assert not "pypi.python.org" in result.stdout, result.stdout
def test_uninstall_from_usersite(self): """ Test uninstall from usersite """ env = reset_env(system_site_packages=True) result1 = run_pip('install', '--user', 'INITools==0.3') result2 = run_pip('uninstall', '-y', 'INITools') assert_all_changes(result1, result2, [env.venv / 'build', 'cache'])
def test_upgrade_vcs_req_with_no_dists_found(): """It can upgrade a VCS requirement that has no distributions otherwise.""" reset_env() req = "%s#egg=pip-test-package" % local_checkout( "git+http://github.com/pypa/pip-test-package.git") run_pip("install", req) result = run_pip("install", "-U", req) assert not result.returncode
def test_uninstall_from_usersite(self): """ Test uninstall from usersite """ env = reset_env(system_site_packages=True) result1 = run_pip('install', '--user', 'INITools==0.3') result2 = run_pip('uninstall', '-y', 'INITools') assert_all_changes(result1, result2, [env.venv/'build', 'cache'])
def test_no_upgrade_unless_requested(): """ No upgrade if not specifically requested. """ reset_env() run_pip('install', 'INITools==0.1', expect_error=True) result = run_pip('install', 'INITools', expect_error=True) assert not result.files_created, 'pip install INITools upgraded when it should not have'
def test_reset_env_system_site_packages_usersite(self): """ reset_env(system_site_packages=True) produces env where a --user install can be found using pkg_resources """ env = reset_env(system_site_packages=True) run_pip('install', '--user', 'INITools==0.2') result = env.run('python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').project_name)") project_name = result.stdout.strip() assert 'INITools'== project_name, "'%s' should be 'INITools'" %project_name
def test_local_flag(): """ Test the behavior of --local flag in the list command """ reset_env() run_pip('install', '-f', find_links, '--no-index', 'simple==1.0') result = run_pip('list', '--local') assert 'simple (1.0)' in result.stdout
def test_setup_py_with_dos_line_endings(): """ It doesn't choke on a setup.py file that uses DOS line endings (\\r\\n). Refs https://github.com/pypa/pip/issues/237 """ reset_env() to_install = os.path.abspath(os.path.join(tests_data, 'packages', 'LineEndings')) run_pip('install', to_install, expect_error=False)
def test_show_with_all_files(): """ Test listing all files in the show command. """ reset_env() result = run_pip('install', 'initools==0.2') result = run_pip('show', '--files', 'initools') assert re.search(r"Files:\n( .+\n)+", result.stdout)
def test_upgrade_if_requested(): """ And it does upgrade if requested. """ env = reset_env() run_pip('install', 'INITools==0.1', expect_error=True) result = run_pip('install', '--upgrade', 'INITools', expect_error=True) assert result.files_created, 'pip install --upgrade did not upgrade' assert env.site_packages/'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
def test_setup_py_with_dos_line_endings(): """ It doesn't choke on a setup.py file that uses DOS line endings (\\r\\n). Refs https://github.com/pypa/pip/issues/237 """ reset_env() to_install = os.path.abspath( os.path.join(tests_data, 'packages', 'LineEndings')) run_pip('install', to_install, expect_error=False)
def test_install_with_ignoreinstalled_requested(): """ It installs package if ignore installed is set. """ env = reset_env() run_pip('install', 'INITools==0.1', expect_error=True) result = run_pip('install', '-I', 'INITools', expect_error=True) assert result.files_created, 'pip install -I did not install' assert env.site_packages/'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
def test_list_command(): """ Test default behavior of list command. """ reset_env() run_pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0') result = run_pip('list') assert 'simple (1.0)' in result.stdout, str(result) assert 'simple2 (3.0)' in result.stdout, str(result)
def test_install_with_ignoreinstalled_requested(): """ It installs package if ignore installed is set. """ env = reset_env() run_pip("install", "INITools==0.1", expect_error=True) result = run_pip("install", "-I", "INITools", expect_error=True) assert result.files_created, "pip install -I did not install" assert env.site_packages / "INITools-0.1-py%s.egg-info" % pyversion not in result.files_created
def _test_uninstall_editable_with_source_outside_venv(tmpdir): env = reset_env() result = env.run('git', 'clone', local_repo('git+git://github.com/pypa/virtualenv'), tmpdir) result2 = run_pip('install', '-e', tmpdir) assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), list(result2.files_created.keys()) result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True) assert_all_changes(result, result3, [env.venv / 'build'])
def test_editables_flag(): """ Test the behavior of --editables flag in the list command """ reset_env() run_pip('install', '-f', find_links, '--no-index', 'simple==1.0') result = run_pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package') result = run_pip('list', '--editable') assert 'simple (1.0)' not in result.stdout, str(result) assert os.path.join('src', 'pip-test-package') in result.stdout, str(result)
def test_upgrade_if_requested(): """ And it does upgrade if requested. """ env = reset_env() run_pip("install", "INITools==0.1", expect_error=True) result = run_pip("install", "--upgrade", "INITools", expect_error=True) assert result.files_created, "pip install --upgrade did not upgrade" assert env.site_packages / "INITools-0.1-py%s.egg-info" % pyversion not in result.files_created
def test_install_with_ignoreinstalled_requested(): """ It installs package if ignore installed is set. """ env = reset_env() run_pip('install', 'INITools==0.1', expect_error=True) result = run_pip('install', '-I', 'INITools', expect_error=True) assert result.files_created, 'pip install -I did not install' assert env.site_packages / 'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
def test_upgrade_if_requested(): """ And it does upgrade if requested. """ env = reset_env() run_pip('install', 'INITools==0.1', expect_error=True) result = run_pip('install', '--upgrade', 'INITools', expect_error=True) assert result.files_created, 'pip install --upgrade did not upgrade' assert env.site_packages / 'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
def test_should_not_install_always_from_cache(): """ If there is an old cached package, pip should download the newer version Related to issue #175 """ env = reset_env() run_pip('install', 'INITools==0.2', expect_error=True) run_pip('uninstall', '-y', 'INITools') result = run_pip('install', 'INITools==0.1', expect_error=True) assert env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion not in result.files_created assert env.site_packages / 'INITools-0.1-py%s.egg-info' % pyversion in result.files_created
def test_upgrade_to_specific_version(): """ It does upgrade to specific version requested. """ env = reset_env() run_pip('install', 'INITools==0.1', expect_error=True) result = run_pip('install', 'INITools==0.2', expect_error=True) assert result.files_created, 'pip install with specific version did not upgrade' assert env.site_packages / 'INITools-0.1-py%s.egg-info' % pyversion in result.files_deleted assert env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
def test_cleanup_after_install(): """ Test clean up after installing a package. """ env = reset_env() run_pip('install', '--no-index', '--find-links=%s' % find_links, 'simple') build = env.venv_path / "build" src = env.venv_path / "src" assert not exists(build), "build/ dir still exists: %s" % build assert not exists(src), "unexpected src/ dir exists: %s" % src env.assert_no_temp()
def test_git_works_with_editable_non_origin_repo(): # set up, create a git repo and install it as editable from a local directory path env = reset_env() version_pkg_path = _create_test_package(env) run_pip("install", "-e", version_pkg_path.abspath) # 'freeze'ing this should not fall over, but should result in stderr output warning result = run_pip("freeze", expect_stderr=True) assert "Error when trying to get requirement" in result.stderr assert "Could not determine repository location" in result.stdout assert "version-pkg==0.1" in result.stdout
def test_cleanup_after_install(): """ Test clean up after installing a package. """ env = reset_env() run_pip('install', '--no-index', '--find-links=%s' % find_links, 'simple') build = env.venv_path/"build" src = env.venv_path/"src" assert not exists(build), "build/ dir still exists: %s" % build assert not exists(src), "unexpected src/ dir exists: %s" % src env.assert_no_temp()
def test_install_user_in_global_virtualenv_with_conflict_fails(self): """ Test user install in --system-site-packages virtualenv with conflict in site fails. """ env = reset_env(system_site_packages=True) result1 = run_pip('install', 'INITools==0.2') result2 = run_pip('install', '--user', 'INITools==0.1', expect_error=True) resultp = env.run('python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').location)") dist_location = resultp.stdout.strip() assert "Will not install to the user site because it will lack sys.path precedence to %s in %s" \ % ('INITools', dist_location) in result2.stdout, result2.stdout
def test_upgrade_with_newest_already_installed(): """ If the newest version of a package is already installed, the package should not be reinstalled and the user should be informed. """ env = reset_env() run_pip('install', '-f', find_links, '--no-index', 'simple') result = run_pip('install', '--upgrade', '-f', find_links, '--no-index', 'simple') assert not result.files_created, 'simple upgraded when it should not have' assert 'already up-to-date' in result.stdout, result.stdout
def test_reset_env_system_site_packages_usersite(self): """ reset_env(system_site_packages=True) produces env where a --user install can be found using pkg_resources """ env = reset_env(system_site_packages=True) run_pip('install', '--user', 'INITools==0.2') result = env.run( 'python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').project_name)" ) project_name = result.stdout.strip() assert 'INITools' == project_name, "'%s' should be 'INITools'" % project_name
def test_uninstall_console_scripts(): """ Test uninstalling a package with more files (console_script entry points, extra directories). """ env = reset_env() args = ['install'] args.append('discover') result = run_pip(*args, **{"expect_error": True}) assert env.bin / 'discover' + env.exe in result.files_created, sorted( result.files_created.keys()) result2 = run_pip('uninstall', 'discover', '-y', expect_error=True) assert_all_changes(result, result2, [env.venv / 'build', 'cache'])
def test_uninstall_before_upgrade(): """ Automatic uninstall-before-upgrade. """ env = reset_env() result = run_pip('install', 'INITools==0.2', expect_error=True) assert env.site_packages / 'initools' in result.files_created, sorted( result.files_created.keys()) result2 = run_pip('install', 'INITools==0.3', expect_error=True) assert result2.files_created, 'upgrade to INITools 0.3 failed' result3 = run_pip('uninstall', 'initools', '-y', expect_error=True) assert_all_changes(result, result3, [env.venv / 'build', 'cache'])
def test_simple_uninstall(): """ Test simple install and uninstall. """ env = reset_env() result = run_pip('install', 'INITools==0.2') assert join(env.site_packages, 'initools') in result.files_created, sorted( result.files_created.keys()) #the import forces the generation of __pycache__ if the version of python supports it env.run('python', '-c', "import initools") result2 = run_pip('uninstall', 'INITools', '-y') assert_all_changes(result, result2, [env.venv / 'build', 'cache'])
def test_cleanup_after_install_from_local_directory(): """ Test clean up after installing from a local directory. """ env = reset_env() to_install = abspath(join(tests_data, 'packages', 'FSPkg')) run_pip('install', to_install, expect_error=False) build = env.venv_path / 'build' src = env.venv_path / 'src' assert not exists(build), "unexpected build/ dir exists: %s" % build assert not exists(src), "unexpected src/ dir exist: %s" % src env.assert_no_temp()