def test_check_complicated_name_broken(script): package_a_path = create_test_package_with_setup( script, name='package_A', version='1.0', install_requires=['Dependency-B>=1.0'], ) dependency_b_path_incompatible = create_test_package_with_setup( script, name='dependency-b', version='0.1', ) # With broken dependency result = script.pip('install', '--no-index', package_a_path, '--no-deps') assert "Successfully installed package-A-1.0" in result.stdout, str(result) result = script.pip( 'install', '--no-index', dependency_b_path_incompatible, '--no-deps', ) assert "Successfully installed dependency-b-0.1" in result.stdout result = script.pip('check', expect_error=True) expected_lines = ( "package-a 1.0 has requirement Dependency-B>=1.0, but you have " "dependency-b 0.1.", ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 1
def test_check_complicated_name_clean(script): package_a_path = create_test_package_with_setup( script, name='package_A', version='1.0', install_requires=['Dependency-B>=1.0'], ) dependency_b_path = create_test_package_with_setup( script, name='dependency-b', version='1.0', ) result = script.pip('install', '--no-index', package_a_path, '--no-deps') assert "Successfully installed package-A-1.0" in result.stdout, str(result) result = script.pip( 'install', '--no-index', dependency_b_path, '--no-deps', ) assert "Successfully installed dependency-b-1.0" in result.stdout result = script.pip('check', expect_error=True) expected_lines = ( "No broken requirements found.", ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 0
def test_check_development_versions_are_also_considered(script): # Setup pkga depending on pkgb>=1.0 pkga_path = create_test_package_with_setup( script, name='pkga', version='1.0', install_requires=['depend>=1.0'], ) # Let's install pkga without its dependency res = script.pip('install', '--no-index', pkga_path, '--no-deps') assert "Successfully installed pkga-1.0" in res.stdout, str(res) # Setup depend==1.1.0.dev0 depend_path = create_test_package_with_setup( script, name='depend', version='1.1.0.dev0', ) # Let's install depend==1.1.0.dev0 res = script.pip( 'install', '--no-index', depend_path, '--no-warn-conflicts', ) assert "Successfully installed depend-1.1.0.dev0" in res.stdout, str(res) result = script.pip('check') expected_lines = ( "No broken requirements found.", ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 0
def test_check_broken_dependency_and_missing_dependency(script): pkga_path = create_test_package_with_setup( script, name='pkga', version='1.0', install_requires=['broken>=1.0'], ) # Let's install pkga without its dependency res = script.pip('install', '--no-index', pkga_path, '--no-deps') assert "Successfully installed pkga-1.0" in res.stdout, str(res) # Setup broken==0.1 broken_path = create_test_package_with_setup( script, name='broken', version='0.1', install_requires=['missing'], ) # Let's install broken==0.1 res = script.pip('install', '--no-index', broken_path, '--no-deps') assert "Successfully installed broken-0.1" in res.stdout, str(res) result = script.pip('check', expect_error=True) expected_lines = ( "broken 0.1 requires missing, which is not installed.", "pkga 1.0 has requirement broken>=1.0, but you have broken 0.1." ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 1
def test_check_install_does_not_warn_for_out_of_graph_issues( script, deprecated_python): pkg_broken_path = create_test_package_with_setup( script, name='broken', version='1.0', install_requires=['missing', 'conflict < 1.0'], ) pkg_unrelated_path = create_test_package_with_setup( script, name='unrelated', version='1.0', ) pkg_conflict_path = create_test_package_with_setup( script, name='conflict', version='1.0', ) # Install a package without it's dependencies result = script.pip('install', '--no-index', pkg_broken_path, '--no-deps') # Deprecated python versions produce an extra warning on stderr assert matches_expected_lines( result.stderr, [], exact=not deprecated_python) # Install conflict package result = script.pip( 'install', '--no-index', pkg_conflict_path, expect_error=True, ) assert matches_expected_lines(result.stderr, [ "ERROR: broken 1.0 requires missing, which is not installed.", ( "ERROR: broken 1.0 has requirement conflict<1.0, but " "you'll have conflict 1.0 which is incompatible." ), ], exact=not deprecated_python) # Install unrelated package result = script.pip( 'install', '--no-index', pkg_unrelated_path, '--quiet', ) # should not warn about broken's deps when installing unrelated package assert matches_expected_lines( result.stderr, [], exact=not deprecated_python) result = script.pip('check', expect_error=True) expected_lines = [ "broken 1.0 requires missing, which is not installed.", "broken 1.0 has requirement conflict<1.0, but you have conflict 1.0.", ] assert matches_expected_lines(result.stdout, expected_lines)
def test_check_install_canonicalization(script, deprecated_python): pkga_path = create_test_package_with_setup( script, name='pkgA', version='1.0', install_requires=['normal-missing', 'SPECIAL.missing'], ) normal_path = create_test_package_with_setup( script, name='normal-missing', version='0.1', ) special_path = create_test_package_with_setup( script, name='SPECIAL.missing', version='0.1', ) # Let's install pkgA without its dependency result = script.pip('install', '--no-index', pkga_path, '--no-deps') assert "Successfully installed pkgA-1.0" in result.stdout, str(result) # Install the first missing dependency. Only an error for the # second dependency should remain. result = script.pip( 'install', '--no-index', normal_path, '--quiet', expect_error=True ) expected_lines = [ "ERROR: pkga 1.0 requires SPECIAL.missing, which is not installed.", ] # Deprecated python versions produce an extra warning on stderr assert matches_expected_lines( result.stderr, expected_lines, exact=not deprecated_python) assert result.returncode == 0 # Install the second missing package and expect that there is no warning # during the installation. This is special as the package name requires # name normalization (as in https://github.com/pypa/pip/issues/5134) result = script.pip( 'install', '--no-index', special_path, '--quiet', ) assert matches_expected_lines( result.stderr, [], exact=not deprecated_python) assert result.returncode == 0 # Double check that all errors are resolved in the end result = script.pip('check') expected_lines = [ "No broken requirements found.", ] assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 0
def test_uninstall_entry_point(script, console_scripts): """ Test uninstall package with two or more entry points in the same section, whose name contain a colon. """ pkg_name = 'ep_install' pkg_path = create_test_package_with_setup( script, name=pkg_name, version='0.1', entry_points={"console_scripts": [console_scripts, ], "pip_test.ep": ["ep:name1 = distutils_install", "ep:name2 = distutils_install"] } ) script_name = script.bin_path.join(console_scripts.split('=')[0].strip()) result = script.pip('install', pkg_path) assert script_name.exists result = script.pip('list', '--format=json') assert {"name": "ep-install", "version": "0.1"} \ in json.loads(result.stdout) script.pip('uninstall', 'ep_install', '-y') assert not script_name.exists result2 = script.pip('list', '--format=json') assert {"name": "ep-install", "version": "0.1"} \ not in json.loads(result2.stdout)
def test_check_complex_names(script): # Check that uppercase letters and '-' are dealt with # Setup two small projects pkga_path = create_test_package_with_setup( script, name='pkga', version='1.0', install_requires=['Complex_Name==0.1'], ) complex_path = create_test_package_with_setup( script, name='Complex-Name', version='0.1', ) res = script.pip('install', '--no-index', complex_path) assert "Successfully installed Complex-Name-0.1" in res.stdout, str(res) res = script.pip('install', '--no-index', pkga_path, '--no-deps') assert "Successfully installed pkga-1.0" in res.stdout, str(res) # Check that Complex_Name is correctly dealt with res = script.pip('check') assert "No broken requirements found." in res.stdout, str(res)
def test_install_pep508_with_url_in_install_requires(script): pkga_path = create_test_package_with_setup( script, name='pkga', version='1.0', install_requires=[ 'packaging@https://files.pythonhosted.org/packages/2f/2b/' 'c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/' 'packaging-15.3-py2.py3-none-any.whl#sha256=' 'ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4' ], ) res = script.pip('install', pkga_path, expect_error=True) assert "Direct url requirement " in res.stderr, str(res) assert "are not allowed for dependencies" in res.stderr, str(res)
def test_uninstall_gui_scripts(script): """ Make sure that uninstall removes gui scripts """ pkg_name = "gui_pkg" pkg_path = create_test_package_with_setup( script, name=pkg_name, version='0.1', entry_points={"gui_scripts": ["test_ = distutils_install", ], } ) script_name = script.bin_path.join('test_') script.pip('install', pkg_path) assert script_name.exists script.pip('uninstall', pkg_name, '-y') assert not script_name.exists
def test_check_complicated_name_missing(script): package_a_path = create_test_package_with_setup( script, name='package_A', version='1.0', install_requires=['Dependency-B>=1.0'], ) # Without dependency result = script.pip('install', '--no-index', package_a_path, '--no-deps') assert "Successfully installed package-A-1.0" in result.stdout, str(result) result = script.pip('check', expect_error=True) expected_lines = ( "package-a 1.0 requires dependency-b, which is not installed.", ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 1
def test_check_missing_dependency(script): # Setup a small project pkga_path = create_test_package_with_setup( script, name='pkga', version='1.0', install_requires=['missing==0.1'], ) # Let's install pkga without its dependency res = script.pip('install', '--no-index', pkga_path, '--no-deps') assert "Successfully installed pkga-1.0" in res.stdout, str(res) result = script.pip('check', expect_error=True) expected_lines = ( "pkga 1.0 requires missing, which is not installed.", ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 1
def test_uninstall_gui_scripts(script): """ Make sure that uninstall removes gui scripts """ pkg_name = "gui_pkg" pkg_path = create_test_package_with_setup( script, name=pkg_name, version='0.1', entry_points={ "gui_scripts": [ "test_ = distutils_install", ], }) script_name = script.bin_path.join('test_') script.pip('install', pkg_path) assert script_name.exists script.pip('uninstall', pkg_name, '-y') assert not script_name.exists
def test_show_skip_work_dir_pkg(script): """ Test that show should not include package present in working directory """ # Create a test package and create .egg-info dir pkg_path = create_test_package_with_setup(script, name='simple', version='1.0') script.run('python', 'setup.py', 'egg_info', expect_stderr=True, cwd=pkg_path) # Show should not include package simple when run from package directory result = script.pip('show', 'simple', expect_error=True, cwd=pkg_path) assert 'WARNING: Package(s) not found: simple' in result.stderr
def test_check_considers_conditional_reqs(script): package_a_path = create_test_package_with_setup( script, name='package_A', version='1.0', install_requires=[ "Dependency-B>=1.0; python_version != '2.7'", "Dependency-B>=2.0; python_version == '2.7'", ], ) result = script.pip('install', '--no-index', package_a_path, '--no-deps') assert "Successfully installed package-A-1.0" in result.stdout, str(result) result = script.pip('check', expect_error=True) expected_lines = ( "package-a 1.0 requires dependency-b, which is not installed.", ) assert matches_expected_lines(result.stdout, expected_lines) assert result.returncode == 1
def test_uninstall_console_scripts(script): """ Test uninstalling a package with more files (console_script entry points, extra directories). """ pkg_path = create_test_package_with_setup( script, name='discover', version='0.1', entry_points={'console_scripts': ['discover = discover:main']}, ) result = script.pip('install', pkg_path) assert script.bin / 'discover' + script.exe in result.files_created, ( sorted(result.files_created.keys())) result2 = script.pip('uninstall', 'discover', '-y') assert_all_changes(result, result2, [ script.venv / 'build', 'cache', script.scratch / 'discover' / 'discover.egg-info', ])
def test_uninstall_console_scripts_uppercase_name(script): """ Test uninstalling console script with uppercase character. """ pkg_path = create_test_package_with_setup( script, name='ep_install', version='0.1', entry_points={ "console_scripts": [ "Test = distutils_install", ], }, ) script_name = script.bin_path.joinpath('Test' + script.exe) script.pip('install', pkg_path) assert script_name.exists() script.pip('uninstall', 'ep_install', '-y') assert not script_name.exists()
def test_new_resolver_installs_editable(script): create_basic_wheel_for_package( script, "base", "0.1.0", depends=["dep"], ) source_dir = create_test_package_with_setup( script, name="dep", version="0.1.0", ) script.pip( "install", "--use-feature=2020-resolver", "--no-cache-dir", "--no-index", "--find-links", script.scratch_path, "base", "--editable", source_dir, ) assert_installed(script, base="0.1.0", dep="0.1.0") assert_editable(script, "dep")
def test_uninstall_console_scripts_uppercase_name( script: PipTestEnvironment) -> None: """ Test uninstalling console script with uppercase character. """ pkg_path = create_test_package_with_setup( script, name="ep_install", version="0.1", entry_points={ "console_scripts": [ "Test = distutils_install", ], }, ) script_name = script.bin_path.joinpath("Test" + script.exe) script.pip("install", pkg_path) assert script_name.exists() script.pip("uninstall", "ep_install", "-y") assert not script_name.exists()
def test_uninstall_gui_scripts(script: PipTestEnvironment) -> None: """ Make sure that uninstall removes gui scripts """ pkg_name = "gui_pkg" pkg_path = create_test_package_with_setup( script, name=pkg_name, version="0.1", entry_points={ "gui_scripts": [ "test_ = distutils_install", ], }, ) script_name = script.bin_path.joinpath("test_") if sys.platform == "win32": script_name += ".exe" script.pip("install", pkg_path) assert script_name.exists() script.pip("uninstall", pkg_name, "-y") assert not script_name.exists()
def test_freeze_include_work_dir_pkg(script: PipTestEnvironment) -> None: """ Test that freeze should include package in working directory if working directory is added in PYTHONPATH """ # Create a test package and create .egg-info dir pkg_path = create_test_package_with_setup(script, name="simple", version="1.0") script.run("python", "setup.py", "egg_info", expect_stderr=True, cwd=pkg_path) script.environ.update({"PYTHONPATH": pkg_path}) # Freeze should include package simple when run from package directory, # when package directory is in PYTHONPATH result = script.pip("freeze", cwd=pkg_path) assert "simple==1.0" in result.stdout
def test_new_resolver_prefers_installed_in_upgrade_if_latest(script): create_basic_wheel_for_package(script, "pkg", "1") local_pkg = create_test_package_with_setup(script, name="pkg", version="2") # Install the version that's not on the index. script.pip( "install", "--no-cache-dir", "--no-index", local_pkg, ) # Now --upgrade should still pick the local version because it's "better". script.pip( "install", "--no-cache-dir", "--no-index", "--find-links", script.scratch_path, "--upgrade", "pkg", ) assert_installed(script, pkg="2")
def test_freeze_include_work_dir_pkg(script): """ Test that freeze should include package in working directory if working directory is added in PYTHONPATH """ # Create a test package and create .egg-info dir pkg_path = create_test_package_with_setup(script, name='simple', version='1.0') script.run('python', 'setup.py', 'egg_info', expect_stderr=True, cwd=pkg_path) script.environ.update({'PYTHONPATH': pkg_path}) # Freeze should include package simple when run from package directory, # when package directory is in PYTHONPATH result = script.pip('freeze', cwd=pkg_path) assert 'simple==1.0' in result.stdout
def test_uninstall_console_scripts(script: PipTestEnvironment) -> None: """ Test uninstalling a package with more files (console_script entry points, extra directories). """ pkg_path = create_test_package_with_setup( script, name="discover", version="0.1", entry_points={"console_scripts": ["discover = discover:main"]}, ) result = script.pip("install", pkg_path) result.did_create(script.bin / "discover" + script.exe) result2 = script.pip("uninstall", "discover", "-y") assert_all_changes( result, result2, [ script.venv / "build", "cache", Path("scratch") / "discover" / "discover.egg-info", ], )
def test_list_include_work_dir_pkg(script): """ Test that list should include package in working directory if working directory is added in PYTHONPATH """ # Create a test package and create .egg-info dir pkg_path = create_test_package_with_setup(script, name='simple', version='1.0') script.run('python', 'setup.py', 'egg_info', expect_stderr=True, cwd=pkg_path) script.environ.update({'PYTHONPATH': pkg_path}) # List should include package simple when run from package directory # when the package directory is in PYTHONPATH result = script.pip('list', '--format=json', cwd=pkg_path) json_result = json.loads(result.stdout) assert {'name': 'simple', 'version': '1.0'} in json_result
def test_list_include_work_dir_pkg(script: PipTestEnvironment) -> None: """ Test that list should include package in working directory if working directory is added in PYTHONPATH """ # Create a test package and create .egg-info dir pkg_path = create_test_package_with_setup(script, name="simple", version="1.0") script.run("python", "setup.py", "egg_info", expect_stderr=True, cwd=pkg_path) script.environ.update({"PYTHONPATH": pkg_path}) # List should include package simple when run from package directory # when the package directory is in PYTHONPATH result = script.pip("list", "--format=json", cwd=pkg_path) json_result = json.loads(result.stdout) assert {"name": "simple", "version": "1.0"} in json_result