class TestCandidateEvaluator(object): # patch this for travis which has distribute in its base env for now @patch( 'pip._internal.wheel.pkg_resources.get_distribution', lambda x: Distribution(project_name='setuptools', version='0.9') ) def setup(self): self.version = '1.0' self.search_name = 'pytest' self.canonical_name = 'pytest' valid_tags = pip._internal.pep425tags.get_supported() self.evaluator = CandidateEvaluator(valid_tags=valid_tags) @pytest.mark.parametrize( 'url', [ 'http:/yo/pytest-1.0.tar.gz', 'http:/yo/pytest-1.0-py2.py3-none-any.whl', ], ) def test_evaluate_link__match(self, url): """Test that 'pytest' archives match for 'pytest'""" link = Link(url) search = Search( supplied=self.search_name, canonical=self.canonical_name, formats=['source', 'binary'], ) result = self.evaluator.evaluate_link(link, search) expected = InstallationCandidate(self.search_name, self.version, link) assert result == expected, result @pytest.mark.parametrize( 'url', [ # TODO: Uncomment this test case when #1217 is fixed. # 'http:/yo/pytest-xdist-1.0.tar.gz', 'http:/yo/pytest2-1.0.tar.gz', 'http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl', ], ) def test_evaluate_link__substring_fails(self, url): """Test that 'pytest<something> archives won't match for 'pytest'.""" link = Link(url) search = Search( supplied=self.search_name, canonical=self.canonical_name, formats=['source', 'binary'], ) result = self.evaluator.evaluate_link(link, search) assert result is None, result
class TestCandidateEvaluator(object): # patch this for travis which has distribute in its base env for now @patch( 'pip._internal.wheel.pkg_resources.get_distribution', lambda x: Distribution(project_name='setuptools', version='0.9') ) def setup(self): self.search_name = 'pytest' self.canonical_name = 'pytest' valid_tags = pip._internal.pep425tags.get_supported() self.evaluator = CandidateEvaluator(valid_tags=valid_tags) @pytest.mark.parametrize('url, expected_version', [ ('http:/yo/pytest-1.0.tar.gz', '1.0'), ('http:/yo/pytest-1.0-py2.py3-none-any.whl', '1.0'), ]) def test_evaluate_link__match(self, url, expected_version): """Test that 'pytest' archives match for 'pytest'""" link = Link(url) search = Search( supplied=self.search_name, canonical=self.canonical_name, formats=['source', 'binary'], ) actual = self.evaluator.evaluate_link(link, search) assert actual == (True, expected_version) @pytest.mark.parametrize('url, expected_msg', [ # TODO: Uncomment this test case when #1217 is fixed. # 'http:/yo/pytest-xdist-1.0.tar.gz', ('http:/yo/pytest2-1.0.tar.gz', 'Missing project version for pytest'), ('http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl', 'wrong project name (not pytest)'), ]) def test_evaluate_link__substring_fails(self, url, expected_msg): """Test that 'pytest<something> archives won't match for 'pytest'.""" link = Link(url) search = Search( supplied=self.search_name, canonical=self.canonical_name, formats=['source', 'binary'], ) actual = self.evaluator.evaluate_link(link, search) assert actual == (False, expected_msg)
def test_evaluate_link__allow_yanked( self, yanked_reason, allow_yanked, expected, ): evaluator = CandidateEvaluator(allow_yanked=allow_yanked) link = Link( 'https://example.com/#egg=twine-1.12', yanked_reason=yanked_reason, ) search = Search( supplied='twine', canonical='twine', formats=['source'], ) actual = evaluator.evaluate_link(link, search=search) assert actual == expected
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
def test_evaluate_link( self, py_version_info, ignore_requires_python, expected, ): link = Link( 'https://example.com/#egg=twine-1.12', requires_python='== 3.6.5', ) search = Search( supplied='twine', canonical='twine', formats=['source'], ) evaluator = CandidateEvaluator( [], py_version_info=py_version_info, ignore_requires_python=ignore_requires_python, ) actual = evaluator.evaluate_link(link, search=search) assert actual == expected