def test_latest_version_invalid(mocker): get = mocker.patch("requests.get") get.return_value.json.return_value = { "releases": { "1.0.1": None, "1.0.2rc1": None } } assert source.get_current_or_latest_version("fr2csv") == (False, "1.0.1")
def current_source_key(self, match): if match.package in self.package_cache: key = self.package_cache[match.package] match.other_version = key.version return key installed, version = source.get_current_or_latest_version( match.package) pypi_key = PyPIKey(match.package, version, installed) self.package_cache[match.package] = pypi_key match.other_version = version return pypi_key
def get_packages(self, match_info): # In order to minimize useless computation, we'll analyze # all the match for a given package at the same time. current_packages = {} for (package, version), package_info in sorted(match_info.items()): current_source = None try: current_source, current_version = current_packages[package] except KeyError: installed, current_version = ( source.get_current_or_latest_version(package)) # If we're comparing the same version, let's not # waste time and resources. if current_version == version: continue files = list(package_info) match_source = self.download_package( package, version, files) if not current_source: if installed: current_source = self.retrieve_installed_package( package, files) else: current_source = self.download_package( package, current_version, files) current_packages[package] = (current_source, current_version) if match_source == current_source: continue self.mark_other_version(match_info, current_version) yield (package, version), (match_source, current_source)
def check_package(self, package, version, matches_package): """ For a given package, extract the sources and call compare_contents """ installed, current_version = ( source.get_current_or_latest_version(package)) # If we're comparing the same version, let's not # waste time and resources. if current_version == version: return for match in matches_package: match.other_version = current_version # Get the list of files for this package # that we'll want to check. We only check those. files = set(match.path for match in matches_package) # If the package is installed, we'll use its source. # Otherwise, we'll download it. if not installed: current_path = self.cleaner.mkdir() source.download_package(package, current_version, current_path) current_content = source.open_downloaded(current_path, files, package) else: current_path = source.get_current_path(package) current_content = source.open_installed(current_path, files) # For the package pointed by the Raincoat comment, we'll always have to # download it. matched_path = self.cleaner.mkdir() source.download_package(package, version, matched_path) match_content = source.open_downloaded(matched_path, files, package) # fast escape strategy if match_content == current_content: return self.compare_contents(match_content, current_content, matches_package)
def test_latest_version(mocker): get = mocker.patch("requests.get") get.return_value.json.return_value = {"info": {"version": "1.0.1"}} assert source.get_current_or_latest_version("fr2csv") == (False, "1.0.1")
def test_current_version(): assert source.get_current_or_latest_version("pytest") == (True, "3.0.3")
def test_current_version(mocker): dist = mocker.patch("raincoat.source.pkg_resources.get_distribution")() dist.version = "1.2.3" assert source.get_current_or_latest_version("pytest") == (True, "1.2.3")
def test_current_version(mocker): mocker.patch("importlib_metadata.version", return_value="1.2.3") assert source.get_current_or_latest_version("pytest") == (True, "1.2.3")
def check(self, matches): __, django_version = source.get_current_or_latest_version("django") match_info = self.get_match_info(matches) return self.check_matches(match_info, django_version)