Exemplo n.º 1
0
    def test_make_candidate_evaluator(
        self,
        allow_all_prereleases,
        prefer_binary,
    ):
        target_python = TargetPython()
        target_python._valid_tags = [('py36', 'none', 'any')]
        candidate_prefs = CandidatePreferences(
            prefer_binary=prefer_binary,
            allow_all_prereleases=allow_all_prereleases,
        )
        finder = PackageFinder(
            search_scope=SearchScope([], []),
            session=PipSession(),
            target_python=target_python,
            allow_yanked=True,
            candidate_prefs=candidate_prefs,
        )

        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 == [('py36', 'none', 'any')]
Exemplo n.º 2
0
 def test_get_tags__uses_cached_value(self):
     """
     Test that get_tags() uses the cached value.
     """
     target_python = TargetPython(py_version_info=None)
     target_python._valid_tags = ['tag-1', 'tag-2']
     actual = target_python.get_tags()
     assert actual == ['tag-1', 'tag-2']
Exemplo n.º 3
0
 def test_create(self, allow_all_prereleases, prefer_binary):
     target_python = TargetPython()
     target_python._valid_tags = [('py36', 'none', 'any')]
     evaluator = CandidateEvaluator.create(
         target_python=target_python,
         allow_all_prereleases=allow_all_prereleases,
         prefer_binary=prefer_binary,
     )
     assert evaluator._allow_all_prereleases == allow_all_prereleases
     assert evaluator._prefer_binary == prefer_binary
     assert evaluator._supported_tags == [('py36', 'none', 'any')]
Exemplo n.º 4
0
 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")]
Exemplo n.º 5
0
    def test_not_find_wheel_not_supported(self, data, monkeypatch):
        """
        Test not finding an unsupported wheel.
        """
        req = install_req_from_line("simple.dist")
        target_python = TargetPython()
        # Make sure no tags will match.
        target_python._valid_tags = []
        finder = make_test_finder(
            find_links=[data.find_links],
            target_python=target_python,
        )

        with pytest.raises(DistributionNotFound):
            finder.find_requirement(req, True)
Exemplo n.º 6
0
 def test_create(self, allow_all_prereleases, prefer_binary):
     target_python = TargetPython()
     target_python._valid_tags = [('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 == [('py36', 'none', 'any')]
Exemplo n.º 7
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")]
Exemplo n.º 8
0
    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 = [
            ('pyT', 'none', 'TEST'),
            ('pyT', 'TEST', 'any'),
            ('pyT', 'none', 'any'),
        ]
        target_python = TargetPython()
        target_python._valid_tags = valid_tags
        evaluator = CandidateEvaluator(
            allow_yanked=True,
            target_python=target_python,
        )
        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 == results2, results2
Exemplo n.º 9
0
 def test_evaluate_link__incompatible_wheel(self):
     """
     Test an incompatible wheel.
     """
     target_python = TargetPython(py_version_info=(3, 6, 4))
     # Set the valid tags to an empty list to make sure nothing matches.
     target_python._valid_tags = []
     evaluator = CandidateEvaluator(target_python=target_python)
     link = Link('https://example.com/sample-1.0-py2.py3-none-any.whl')
     search = Search(
         supplied='sample',
         canonical='sample',
         formats=['binary'],
     )
     actual = evaluator.evaluate_link(link, search=search)
     expected = (
         False,
         "none of the wheel's tags match: py2-none-any, py3-none-any")
     assert actual == expected
Exemplo n.º 10
0
 def test_evaluate_link__incompatible_wheel(self):
     """
     Test an incompatible wheel.
     """
     target_python = TargetPython(py_version_info=(3, 6, 4))
     # Set the valid tags to an empty list to make sure nothing matches.
     target_python._valid_tags = []
     evaluator = LinkEvaluator(
         project_name='sample',
         canonical_name='sample',
         formats={'binary'},
         target_python=target_python,
         allow_yanked=True,
     )
     link = Link('https://example.com/sample-1.0-py2.py3-none-any.whl')
     actual = evaluator.evaluate_link(link)
     expected = (
         False,
         "none of the wheel's tags match: py2-none-any, py3-none-any")
     assert actual == expected
Exemplo n.º 11
0
    def test_make_candidate_evaluator(
        self, allow_all_prereleases, prefer_binary,
    ):
        target_python = TargetPython()
        target_python._valid_tags = [('py36', 'none', 'any')]
        candidate_prefs = CandidatePreferences(
            prefer_binary=prefer_binary,
            allow_all_prereleases=allow_all_prereleases,
        )
        finder = PackageFinder(
            search_scope=SearchScope([], []),
            session=PipSession(),
            target_python=target_python,
            allow_yanked=True,
            candidate_prefs=candidate_prefs,
        )

        evaluator = finder.make_candidate_evaluator()
        assert evaluator._allow_all_prereleases == allow_all_prereleases
        assert evaluator._prefer_binary == prefer_binary
        assert evaluator._supported_tags == [('py36', 'none', 'any')]
Exemplo n.º 12
0
 def test_evaluate_link__incompatible_wheel(self) -> None:
     """
     Test an incompatible wheel.
     """
     target_python = TargetPython(py_version_info=(3, 6, 4))
     # Set the valid tags to an empty list to make sure nothing matches.
     target_python._valid_tags = []
     evaluator = LinkEvaluator(
         project_name="sample",
         canonical_name="sample",
         formats=frozenset(["binary"]),
         target_python=target_python,
         allow_yanked=True,
     )
     link = Link("https://example.com/sample-1.0-py2.py3-none-any.whl")
     actual = evaluator.evaluate_link(link)
     expected = (
         False,
         "none of the wheel's tags (py2-none-any, py3-none-any) are compatible "
         "(run pip debug --verbose to show compatible tags)",
     )
     assert actual == expected
Exemplo n.º 13
0
 def test_create__candidate_evaluator(
     self, allow_all_prereleases, prefer_binary,
 ):
     """
     Test that the candidate_evaluator attribute is set correctly.
     """
     selection_prefs = SelectionPreferences(
         allow_yanked=True,
         allow_all_prereleases=allow_all_prereleases,
         prefer_binary=prefer_binary,
     )
     target_python = TargetPython(py_version_info=(3, 7, 3))
     target_python._valid_tags = ['tag1', 'tag2']
     finder = PackageFinder.create(
         search_scope=SearchScope([], []),
         selection_prefs=selection_prefs,
         session=PipSession(),
         target_python=target_python,
     )
     evaluator = finder.candidate_evaluator
     assert evaluator.allow_all_prereleases == allow_all_prereleases
     assert evaluator._prefer_binary == prefer_binary
     assert evaluator._supported_tags == ['tag1', 'tag2']
Exemplo n.º 14
0
    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")]