def find_best_match(self, ireq, prereleases=False): if ireq.editable: return ireq versions = list(ireq.specifier.filter(self.index[key_from_ireq(ireq)], prereleases=prereleases)) if not versions: raise NoCandidateFound(ireq, self.index[key_from_ireq(ireq)], ['https://fake.url.foo']) best_version = max(versions, key=Version) return make_install_requirement( name_from_req(ireq).lower(), best_version, ireq.extras, constraint=ireq.constraint)
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_no_upgrades(base_resolver, repository, from_line, input, pins, expected): input = [from_line(line) for line in input] existing_pins = dict() for line in pins: ireq = from_line(line) existing_pins[key_from_ireq(ireq)] = ireq local_repository = LocalRequirementsRepository(existing_pins, repository) output = base_resolver(input, prereleases=False, repository=local_repository).resolve() output = {str(line) for line in output} assert output == {str(line) for line in expected}
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'