def test_get_tags__uses_cached_value(self) -> None: """ Test that get_tags() uses the cached value. """ target_python = TargetPython(py_version_info=None) target_python._valid_tags = [ Tag("py2", "none", "any"), Tag("py3", "none", "any"), ] actual = target_python.get_tags() assert actual == [Tag("py2", "none", "any"), Tag("py3", "none", "any")]
def test_support_index_min(self): """ Test results from `support_index_min` """ tags = [ Tag('py2', 'none', 'TEST'), Tag('py2', 'TEST', 'any'), Tag('py2', 'none', 'any'), ] w = Wheel('simple-0.1-py2-none-any.whl') assert w.support_index_min(tags=tags) == 2 w = Wheel('simple-0.1-py2-none-TEST.whl') assert w.support_index_min(tags=tags) == 0
def test_support_index_min(self) -> None: """ Test results from `support_index_min` """ tags = [ Tag("py2", "none", "TEST"), Tag("py2", "TEST", "any"), Tag("py2", "none", "any"), ] w = Wheel("simple-0.1-py2-none-any.whl") assert w.support_index_min(tags=tags) == 2 w = Wheel("simple-0.1-py2-none-TEST.whl") assert w.support_index_min(tags=tags) == 0
def test_create(self, allow_all_prereleases: bool, prefer_binary: bool) -> None: target_python = TargetPython() target_python._valid_tags = [Tag("py36", "none", "any")] specifier = SpecifierSet() evaluator = CandidateEvaluator.create( project_name="my-project", target_python=target_python, allow_all_prereleases=allow_all_prereleases, prefer_binary=prefer_binary, specifier=specifier, ) assert evaluator._allow_all_prereleases == allow_all_prereleases assert evaluator._prefer_binary == prefer_binary assert evaluator._specifier is specifier assert evaluator._supported_tags == [Tag("py36", "none", "any")]
def __init__(self, filename): # type: (str) -> None """ :raises InvalidWheelFilename: when the filename is invalid for a wheel """ wheel_info = self.wheel_file_re.match(filename) if not wheel_info: raise InvalidWheelFilename( "%s is not a valid wheel filename." % filename ) self.filename = filename self.name = wheel_info.group('name').replace('_', '-') # we'll assume "_" means "-" due to wheel naming scheme # (https://github.com/pypa/pip/issues/1150) self.version = wheel_info.group('ver').replace('_', '-') self.build_tag = wheel_info.group('build') self.pyversions = wheel_info.group('pyver').split('.') self.abis = wheel_info.group('abi').split('.') self.plats = wheel_info.group('plat').split('.') # All the tag combinations from this file self.file_tags = { Tag(x, y, z) for x in self.pyversions for y in self.abis for z in self.plats }
def test_wheel_name_filter(tmpdir: Path) -> None: """ Test the wheel cache filters on wheel name when several wheels for different package are stored under the same cache directory. """ wc = WheelCache(tmpdir, FormatControl()) link = Link("https://g.c/package.tar.gz") cache_path = wc.get_path_for_link(link) ensure_dir(cache_path) with open(os.path.join(cache_path, "package-1.0-py3-none-any.whl"), "w"): pass # package matches wheel name cached_link = wc.get(link, "package", [Tag("py3", "none", "any")]) assert cached_link is not link assert os.path.exists(cached_link.file_path) # package2 does not match wheel name assert wc.get(link, "package2", [Tag("py3", "none", "any")]) is link
def test_link_sorting(self) -> None: """ Test link sorting """ links = [ InstallationCandidate("simple", "2.0", Link("simple-2.0.tar.gz")), InstallationCandidate( "simple", "1.0", Link("simple-1.0-pyT-none-TEST.whl"), ), InstallationCandidate( "simple", "1.0", Link("simple-1.0-pyT-TEST-any.whl"), ), InstallationCandidate( "simple", "1.0", Link("simple-1.0-pyT-none-any.whl"), ), InstallationCandidate( "simple", "1.0", Link("simple-1.0.tar.gz"), ), ] valid_tags = [ Tag("pyT", "none", "TEST"), Tag("pyT", "TEST", "any"), Tag("pyT", "none", "any"), ] specifier = SpecifierSet() evaluator = CandidateEvaluator( "my-project", supported_tags=valid_tags, specifier=specifier, ) sort_key = evaluator._sort_key results = sorted(links, key=sort_key, reverse=True) results2 = sorted(reversed(links), key=sort_key, reverse=True) assert links == results, results assert links == results2, results2
def test_link_sorting(self): """ Test link sorting """ links = [ InstallationCandidate("simple", "2.0", Link('simple-2.0.tar.gz')), InstallationCandidate( "simple", "1.0", Link('simple-1.0-pyT-none-TEST.whl'), ), InstallationCandidate( "simple", '1.0', Link('simple-1.0-pyT-TEST-any.whl'), ), InstallationCandidate( "simple", '1.0', Link('simple-1.0-pyT-none-any.whl'), ), InstallationCandidate( "simple", '1.0', Link('simple-1.0.tar.gz'), ), ] valid_tags = [ Tag('pyT', 'none', 'TEST'), Tag('pyT', 'TEST', 'any'), Tag('pyT', 'none', 'any'), ] specifier = SpecifierSet() evaluator = CandidateEvaluator( 'my-project', supported_tags=valid_tags, specifier=specifier, ) sort_key = evaluator._sort_key results = sorted(links, key=sort_key, reverse=True) results2 = sorted(reversed(links), key=sort_key, reverse=True) assert links == results, results assert links == results2, results2
def test_build_tag_is_less_important_than_other_tags(self) -> None: links = [ InstallationCandidate( "simple", "1.0", Link("simple-1.0-1-py3-abi3-linux_x86_64.whl"), ), InstallationCandidate( "simple", "1.0", Link("simple-1.0-2-py3-abi3-linux_i386.whl"), ), InstallationCandidate( "simple", "1.0", Link("simple-1.0-2-py3-any-none.whl"), ), InstallationCandidate( "simple", "1.0", Link("simple-1.0.tar.gz"), ), ] valid_tags = [ Tag("py3", "abi3", "linux_x86_64"), Tag("py3", "abi3", "linux_i386"), Tag("py3", "any", "none"), ] evaluator = CandidateEvaluator( "my-project", supported_tags=valid_tags, specifier=SpecifierSet(), ) sort_key = evaluator._sort_key results = sorted(links, key=sort_key, reverse=True) results2 = sorted(reversed(links), key=sort_key, reverse=True) assert links == results, results assert links == results2, results2
def test_build_tag_is_less_important_than_other_tags(self): links = [ InstallationCandidate( "simple", "1.0", Link('simple-1.0-1-py3-abi3-linux_x86_64.whl'), ), InstallationCandidate( "simple", '1.0', Link('simple-1.0-2-py3-abi3-linux_i386.whl'), ), InstallationCandidate( "simple", '1.0', Link('simple-1.0-2-py3-any-none.whl'), ), InstallationCandidate( "simple", '1.0', Link('simple-1.0.tar.gz'), ), ] valid_tags = [ Tag('py3', 'abi3', 'linux_x86_64'), Tag('py3', 'abi3', 'linux_i386'), Tag('py3', 'any', 'none'), ] evaluator = CandidateEvaluator( 'my-project', supported_tags=valid_tags, specifier=SpecifierSet(), ) sort_key = evaluator._sort_key results = sorted(links, key=sort_key, reverse=True) results2 = sorted(reversed(links), key=sort_key, reverse=True) assert links == results, results assert links == results2, results2
def test_get_with_legacy_entry_only(tmpdir): """ Test that an existing cache entry that was created with the legacy hashing mechanism is actually returned in WheelCache.get(). """ wc = WheelCache(tmpdir, FormatControl()) link = Link("https://g.c/o/r") legacy_path = wc.get_path_for_link_legacy(link) ensure_dir(legacy_path) with open(os.path.join(legacy_path, "test-1.0.0-py3-none-any.whl"), "w"): pass cached_link = wc.get(link, "test", [Tag("py3", "none", "any")]) assert (os.path.normcase(os.path.dirname( cached_link.file_path)) == os.path.normcase(legacy_path))
def test_make_candidate_evaluator( self, allow_all_prereleases: bool, prefer_binary: bool, ) -> None: target_python = TargetPython() target_python._valid_tags = [Tag("py36", "none", "any")] candidate_prefs = CandidatePreferences( prefer_binary=prefer_binary, allow_all_prereleases=allow_all_prereleases, ) link_collector = LinkCollector( session=PipSession(), search_scope=SearchScope([], []), ) finder = PackageFinder( link_collector=link_collector, target_python=target_python, allow_yanked=True, candidate_prefs=candidate_prefs, use_deprecated_html5lib=False, ) specifier = SpecifierSet() # Pass hashes to check that _hashes is set. hashes = Hashes({"sha256": [64 * "a"]}) evaluator = finder.make_candidate_evaluator( "my-project", specifier=specifier, hashes=hashes, ) assert evaluator._allow_all_prereleases == allow_all_prereleases assert evaluator._hashes == hashes assert evaluator._prefer_binary == prefer_binary assert evaluator._project_name == "my-project" assert evaluator._specifier is specifier assert evaluator._supported_tags == [Tag("py36", "none", "any")]
def test_get_cache_entry(tmpdir): wc = WheelCache(tmpdir, FormatControl()) persi_link = Link("https://g.c/o/r/persi") persi_path = wc.get_path_for_link(persi_link) ensure_dir(persi_path) with open(os.path.join(persi_path, "persi-1.0.0-py3-none-any.whl"), "w"): pass ephem_link = Link("https://g.c/o/r/ephem") ephem_path = wc.get_ephem_path_for_link(ephem_link) ensure_dir(ephem_path) with open(os.path.join(ephem_path, "ephem-1.0.0-py3-none-any.whl"), "w"): pass other_link = Link("https://g.c/o/r/other") supported_tags = [Tag("py3", "none", "any")] assert (wc.get_cache_entry(persi_link, "persi", supported_tags).persistent) assert (not wc.get_cache_entry(ephem_link, "ephem", supported_tags).persistent) assert wc.get_cache_entry(other_link, "other", supported_tags) is None
def __init__(self, filename: str) -> None: """ :raises InvalidWheelFilename: when the filename is invalid for a wheel """ wheel_info = self.wheel_file_re.match(filename) if not wheel_info: raise InvalidWheelFilename(f"{filename} is not a valid wheel filename.") self.filename = filename self.name = wheel_info.group("name").replace("_", "-") # we'll assume "_" means "-" due to wheel naming scheme # (https://github.com/pypa/pip/issues/1150) self.version = wheel_info.group("ver").replace("_", "-") self.build_tag = wheel_info.group("build") self.pyversions = wheel_info.group("pyver").split(".") self.abis = wheel_info.group("abi").split(".") self.plats = wheel_info.group("plat").split(".") # All the tag combinations from this file self.file_tags = { Tag(x, y, z) for x in self.pyversions for y in self.abis for z in self.plats }
def test_not_supported_version(self) -> None: """ Test unsupported wheel is known to be unsupported """ w = Wheel("simple-0.1-py2-none-any.whl") assert not w.supported(tags=[Tag("py1", "none", "any")])
def test_supported_multi_version(self): """ Test multi-version wheel is known to be supported """ w = Wheel('simple-0.1-py2.py3-none-any.whl') assert w.supported(tags=[Tag('py3', 'none', 'any')])
def test_supported_single_version(self): """ Test single-version wheel is known to be supported """ w = Wheel('simple-0.1-py2-none-any.whl') assert w.supported(tags=[Tag('py2', 'none', 'any')])
def test_supported_single_version(self) -> None: """ Test single-version wheel is known to be supported """ w = Wheel("simple-0.1-py2-none-any.whl") assert w.supported(tags=[Tag("py2", "none", "any")])
def test_not_supported_version(self): """ Test unsupported wheel is known to be unsupported """ w = Wheel('simple-0.1-py2-none-any.whl') assert not w.supported(tags=[Tag('py1', 'none', 'any')])
def test_supported_multi_version(self) -> None: """ Test multi-version wheel is known to be supported """ w = Wheel("simple-0.1-py2.py3-none-any.whl") assert w.supported(tags=[Tag("py3", "none", "any")])