def test_find_best_match_preserves_period(): fallback_repo = mock.create_autospec(PyPIRepository) pin = ireq('foo.bar==42.0') existing_pins = {key_from_ireq(pin): pin} repo = LocalRequirementsRepository(existing_pins, fallback_repo) result = repo.find_best_match(ireq('foo.bar')) assert repr(result) == repr(ireq('foo.bar==42.0'))
def test_get_hashes_local_repository_cache_miss(from_line): pip_command = get_pip_command() pip_options, _ = pip_command.parse_args([]) session = pip_command._build_session(pip_options) repository = PyPIRepository(pip_options, session) existing_pins = {} local_repository = LocalRequirementsRepository(existing_pins, repository) hashes = local_repository.get_hashes(from_line('cffi==1.9.1')) assert all(x in EXPECTED for x in hashes) assert hashes
def test_get_hashes_local_repository_cache_hit(from_line, repository): # Create an install requirement with the hashes included in its options options = {} options['hashes'] = {'sha256': [entry.split(':')[1] for entry in EXPECTED]} req = from_line('cffi==1.9.1', options=options) existing_pins = {name_from_req(req): req} # Use fake repository so that we know the hashes are coming from cache local_repository = LocalRequirementsRepository(existing_pins, repository) hashes = local_repository.get_hashes(from_line('cffi==1.9.1')) assert all(x in EXPECTED for x in hashes) assert hashes
def test_find_best_match(existing_pin, to_find, pin_matches, pinned_extras, requested_extras): fallback_repo = mock.create_autospec(PyPIRepository) fallback_repo.find_best_match.return_value = 'fallback_result' pin = ireq(existing_pin, pinned_extras) if existing_pin else None existing_pins = {key_from_ireq(pin): pin} if pin else {} repo = LocalRequirementsRepository(existing_pins, fallback_repo) ireq_to_find = ireq(to_find, requested_extras) result = repo.find_best_match(ireq_to_find) if pin_matches: assert repr(result) == repr(ireq(existing_pin, requested_extras)) else: fallback_repo.find_best_match.assert_called_with(ireq_to_find, None) assert result == 'fallback_result'