def test_install_requirements_with_options(self, tmpdir, finder, session, options): global_option = '--dry-run' install_option = '--prefix=/opt' content = ''' --only-binary :all: INITools==2.0 --global-option="{global_option}" \ --install-option "{install_option}" '''.format(global_option=global_option, install_option=install_option) with requirements_file(content, tmpdir) as reqs_file: req = next(parse_requirements(reqs_file.abspath, finder=finder, options=options, session=session)) req.source_dir = os.curdir with patch.object(subprocess, 'Popen') as popen: popen.return_value.stdout.readline.return_value = b"" try: req.install([]) except: pass last_call = popen.call_args_list[-1] args = last_call[0][0] assert ( 0 < args.index(global_option) < args.index('install') < args.index(install_option) ) assert options.format_control.no_binary == {':all:'} assert options.format_control.only_binary == set()
def test_double_install_spurious_hash_mismatch(script, tmpdir): """Make sure installing the same hashed sdist twice doesn't throw hash mismatch errors. Really, this is a test that we disable reads from the wheel cache in hash-checking mode. Locally, implicitly built wheels of sdists obviously have different hashes from the original archives. Comparing against those causes spurious mismatch errors. """ script.pip('install', 'wheel') # Otherwise, it won't try to build wheels. with requirements_file('simple==1.0 --hash=sha256:393043e672415891885c9a2a' '0929b1af95fb866d6ca016b42d2e6ce53619b653', tmpdir) as reqs_file: # Install a package (and build its wheel): result = script.pip_install_local( '-r', reqs_file.abspath, expect_error=False) assert 'Successfully installed simple-1.0' in str(result) # Uninstall it: script.pip('uninstall', '-y', 'simple', expect_error=False) # Then install it again. We should not hit a hash mismatch, and the # package should install happily. result = script.pip_install_local( '-r', reqs_file.abspath, expect_error=False) assert 'Successfully installed simple-1.0' in str(result)
def test_missing_hash_with_require_hashes_in_reqs_file(self, data, tmpdir): """--require-hashes in a requirements file should make its way to the RequirementSet. """ req_set = self.basic_reqset(require_hashes=False) session = PipSession() finder = PackageFinder([data.find_links], [], session=session) command = InstallCommand() with requirements_file("--require-hashes", tmpdir) as reqs_file: options, args = command.parse_args(["-r", reqs_file]) command.populate_requirement_set(req_set, args, options, finder, session, command.name, wheel_cache=None) assert req_set.require_hashes
def test_relative_requirements_file(script, data): """ Test installing from a requirements file with a relative path. For path URLs, use an egg= definition. """ egg_info_file = ( script.site_packages / 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion ) egg_link_file = ( script.site_packages / 'FSPkg.egg-link' ) package_folder = script.site_packages / 'fspkg' # Compute relative install path to FSPkg from scratch path. full_rel_path = data.packages.join('FSPkg') - script.scratch_path full_rel_url = 'file:' + full_rel_path + '#egg=FSPkg' embedded_rel_path = script.scratch_path.join(full_rel_path) # For each relative path, install as either editable or not using either # URLs with egg links or not. for req_path in (full_rel_path, full_rel_url, embedded_rel_path): req_path = req_path.replace(os.path.sep, '/') # Regular install. with requirements_file(req_path + '\n', script.scratch_path) as reqs_file: result = script.pip('install', '-vvv', '-r', reqs_file.name, cwd=script.scratch_path) assert egg_info_file in result.files_created, str(result) assert package_folder in result.files_created, str(result) script.pip('uninstall', '-y', 'fspkg') # Editable install. with requirements_file('-e ' + req_path + '\n', script.scratch_path) as reqs_file: result = script.pip('install', '-vvv', '-r', reqs_file.name, cwd=script.scratch_path) assert egg_link_file in result.files_created, str(result) script.pip('uninstall', '-y', 'fspkg')
def test_missing_hash_with_require_hashes_in_reqs_file(self, data, tmpdir): """--require-hashes in a requirements file should make its way to the RequirementSet. """ req_set = RequirementSet(require_hashes=False) finder = make_test_finder(find_links=[data.find_links]) session = finder._link_collector.session command = create_command('install') with requirements_file('--require-hashes', tmpdir) as reqs_file: options, args = command.parse_args(['-r', reqs_file]) command.populate_requirement_set( req_set, args, options, finder, session, wheel_cache=None, ) assert req_set.require_hashes
def test_missing_hash_with_require_hashes_in_reqs_file(self, data, tmpdir): """--require-hashes in a requirements file should make its way to the RequirementSet. """ req_set = self.basic_reqset(require_hashes=False) session = PipSession() finder = PackageFinder([data.find_links], [], session=session) command = InstallCommand() with requirements_file('--require-hashes', tmpdir) as reqs_file: options, args = command.parse_args(['-r', reqs_file]) command.populate_requirement_set( req_set, args, options, finder, session, command.name, wheel_cache=None) assert req_set.require_hashes
def test_hashed_install_failure(script, data, tmpdir): """Test that wrong hashes stop installation. This makes sure prepare_files() is called in the course of installation and so has the opportunity to halt if hashes are wrong. Checks on various kinds of hashes are in test_req.py. """ with requirements_file('simple2==1.0 --hash=sha256:9336af72ca661e6336eb87b' 'c7de3e8844d853e3848c2b9bbd2e8bf01db88c2c\n', tmpdir) as reqs_file: result = script.pip_install_local('-r', reqs_file.abspath, expect_error=True) assert len(result.files_created) == 0
def test_hashed_install_success(script, data, tmpdir): """ Test that installing various sorts of requirements with correct hashes works. Test file URLs and index packages (which become HTTP URLs behind the scenes). """ file_url = path_to_url((data.packages / 'simple-1.0.tar.gz').abspath) with requirements_file( 'simple2==1.0 --hash=sha256:9336af72ca661e6336eb87bc7de3e8844d853e' '3848c2b9bbd2e8bf01db88c2c7\n' '{simple} --hash=sha256:393043e672415891885c9a2a0929b1af95fb866d6c' 'a016b42d2e6ce53619b653'.format(simple=file_url), tmpdir) as reqs_file: script.pip_install_local('-r', reqs_file.abspath, expect_error=False)
def test_hashed_install_success(script, data, tmpdir): """ Test that installing various sorts of requirements with correct hashes works. Test file URLs and index packages (which become HTTP URLs behind the scenes). """ file_url = path_to_url( (data.packages / 'simple-1.0.tar.gz').abspath) with requirements_file( 'simple2==1.0 --hash=sha256:9336af72ca661e6336eb87bc7de3e8844d853e' '3848c2b9bbd2e8bf01db88c2c7\n' '{simple} --hash=sha256:393043e672415891885c9a2a0929b1af95fb866d6c' 'a016b42d2e6ce53619b653'.format(simple=file_url), tmpdir) as reqs_file: script.pip_install_local('-r', reqs_file.abspath, expect_error=False)
def test_double_install_spurious_hash_mismatch(script, tmpdir, data, common_wheels): """Make sure installing the same hashed sdist twice doesn't throw hash mismatch errors. Really, this is a test that we disable reads from the wheel cache in hash-checking mode. Locally, implicitly built wheels of sdists obviously have different hashes from the original archives. Comparing against those causes spurious mismatch errors. """ # Install wheel package, otherwise, it won't try to build wheels. script.pip('install', 'wheel', '--no-index', '-f', common_wheels) with requirements_file( 'simple==1.0 --hash=sha256:393043e672415891885c9a2a' '0929b1af95fb866d6ca016b42d2e6ce53619b653', tmpdir) as reqs_file: # Install a package (and build its wheel): result = script.pip_install_local('--find-links', data.find_links, '-f', common_wheels, '-r', reqs_file.abspath, expect_error=False) assert 'Successfully installed simple-1.0' in str(result) # Uninstall it: script.pip('uninstall', '-y', 'simple', expect_error=False) # Then install it again. We should not hit a hash mismatch, and the # package should install happily. result = script.pip_install_local('--find-links', data.find_links, '-f', common_wheels, '-r', reqs_file.abspath, expect_error=False) assert 'Successfully installed simple-1.0' in str(result)
def test_double_install_spurious_hash_mismatch( script: PipTestEnvironment, tmpdir: Path, data: TestData ) -> None: """Make sure installing the same hashed sdist twice doesn't throw hash mismatch errors. Really, this is a test that we disable reads from the wheel cache in hash-checking mode. Locally, implicitly built wheels of sdists obviously have different hashes from the original archives. Comparing against those causes spurious mismatch errors. """ # Install wheel package, otherwise, it won't try to build wheels. with requirements_file( "simple==1.0 --hash=sha256:393043e672415891885c9a2a" "0929b1af95fb866d6ca016b42d2e6ce53619b653", tmpdir, ) as reqs_file: # Install a package (and build its wheel): result = script.pip_install_local( "--find-links", data.find_links, "-r", reqs_file.resolve(), ) assert "Successfully installed simple-1.0" in str(result) # Uninstall it: script.pip("uninstall", "-y", "simple") # Then install it again. We should not hit a hash mismatch, and the # package should install happily. result = script.pip_install_local( "--find-links", data.find_links, "-r", reqs_file.resolve(), ) assert "Successfully installed simple-1.0" in str(result)
def test_install_requirements_with_options( self, tmpdir: Path, finder: PackageFinder, session: PipSession, options: mock.Mock, ) -> None: global_option = "--dry-run" install_option = "--prefix=/opt" content = """ --only-binary :all: INITools==2.0 --global-option="{global_option}" \ --install-option "{install_option}" """.format(global_option=global_option, install_option=install_option) with requirements_file(content, tmpdir) as reqs_file: req = next( parse_reqfile(reqs_file.resolve(), finder=finder, options=options, session=session)) req.source_dir = os.curdir with mock.patch.object(subprocess, "Popen") as popen: popen.return_value.stdout.readline.return_value = b"" try: req.install([]) except Exception: pass last_call = popen.call_args_list[-1] args = last_call[0][0] assert (0 < args.index(global_option) < args.index("install") < args.index(install_option)) assert options.format_control.no_binary == {":all:"} assert options.format_control.only_binary == set()