예제 #1
0
    def test_compatible(self, caplog):
        """
        Test a Python version compatible with the dist's Requires-Python.
        """
        caplog.set_level(logging.DEBUG)
        dist = make_fake_dist('== 3.6.5')

        _check_dist_requires_python(
            dist,
            version_info=(3, 6, 5),
            ignore_requires_python=False,
        )
        assert not len(caplog.records)
예제 #2
0
 def test_incompatible(self):
     """
     Test a Python version incompatible with the dist's Requires-Python.
     """
     dist = make_fake_dist('== 3.6.4')
     with pytest.raises(UnsupportedPythonVersion) as exc:
         _check_dist_requires_python(
             dist,
             version_info=(3, 6, 5),
             ignore_requires_python=False,
         )
     assert str(
         exc.value) == ("Package 'my-project' requires a different Python: "
                        "3.6.5 not in '== 3.6.4'")
예제 #3
0
    def test_none_requires_python(self, caplog):
        """
        Test a dist with Requires-Python None.
        """
        caplog.set_level(logging.DEBUG)
        dist = make_fake_dist()
        # Make sure our test setup is correct.
        assert get_requires_python(dist) is None
        assert len(caplog.records) == 0

        # Then there is no exception and no log message.
        _check_dist_requires_python(
            dist,
            version_info=(3, 6, 5),
            ignore_requires_python=False,
        )
        assert len(caplog.records) == 0
예제 #4
0
 def test_invalid_requires_python(self, caplog):
     """
     Test a dist with an invalid Requires-Python.
     """
     caplog.set_level(logging.DEBUG)
     dist = make_fake_dist('invalid')
     _check_dist_requires_python(
         dist,
         version_info=(3, 6, 5),
         ignore_requires_python=False,
     )
     assert len(caplog.records) == 1
     record = caplog.records[0]
     assert record.levelname == 'WARNING'
     assert record.message == (
         "Package 'my-project' has an invalid Requires-Python: "
         "Invalid specifier: 'invalid'")
예제 #5
0
 def test_incompatible_with_ignore_requires(self, caplog):
     """
     Test a Python version incompatible with the dist's Requires-Python
     while passing ignore_requires_python=True.
     """
     caplog.set_level(logging.DEBUG)
     dist = make_fake_dist('== 3.6.4')
     _check_dist_requires_python(
         dist,
         version_info=(3, 6, 5),
         ignore_requires_python=True,
     )
     assert len(caplog.records) == 1
     record = caplog.records[0]
     assert record.levelname == 'DEBUG'
     assert record.message == (
         "Ignoring failed Requires-Python check for package 'my-project': "
         "3.6.5 not in '== 3.6.4'")
예제 #6
0
    def test_empty_metadata_error(self, metadata_name: str) -> None:
        """Test dist.metadata raises FileNotFoundError."""
        class NotWorkingFakeDist(FakeDist):
            @property
            def metadata(self) -> email.message.Message:
                raise FileNotFoundError(metadata_name)

        dist = make_fake_dist(klass=NotWorkingFakeDist)

        with pytest.raises(NoneMetadataError) as exc:
            _check_dist_requires_python(
                dist,
                version_info=(3, 6, 5),
                ignore_requires_python=False,
            )
        assert str(
            exc.value) == ("None {} metadata found for distribution: "
                           "<distribution 'my-project'>".format(metadata_name))
예제 #7
0
    def test_empty_metadata_error(self, caplog, metadata_name):
        """
        Test dist.has_metadata() returning True and dist.get_metadata()
        returning None.
        """
        dist = make_fake_dist(metadata_name=metadata_name)
        dist.metadata = None

        # Make sure our test setup is correct.
        assert dist.has_metadata(metadata_name)
        assert dist.get_metadata(metadata_name) is None

        with pytest.raises(NoneMetadataError) as exc:
            _check_dist_requires_python(
                dist,
                version_info=(3, 6, 5),
                ignore_requires_python=False,
            )
        assert str(
            exc.value) == ("None {} metadata found for distribution: "
                           "<distribution 'my-project'>".format(metadata_name))