Example #1
0
    def test_package_not_found_mentions_metadata(self):
        """
        When a package is not found, that could indicate that the
        packgae is not installed or that it is installed without
        metadata. Ensure the exception mentions metadata to help
        guide users toward the cause. See #124.
        """
        with self.assertRaises(PackageNotFoundError) as ctx:
            Distribution.from_name('does-not-exist')

        assert "metadata" in str(ctx.exception)
Example #2
0
    def test_more_complex_deps_requires_text(self):
        requires = textwrap.dedent("""
            dep1
            dep2

            [:python_version < "3"]
            dep3

            [extra1]
            dep4

            [extra2:python_version < "3"]
            dep5
            """)
        deps = sorted(Distribution._deps_from_requires_text(requires))
        expected = [
            'dep1',
            'dep2',
            'dep3; python_version < "3"',
            'dep4; extra == "extra1"',
            'dep5; (python_version < "3") and extra == "extra2"',
        ]
        # It's important that the environment marker expression be
        # wrapped in parentheses to avoid the following 'and' binding more
        # tightly than some other part of the environment expression.

        assert deps == expected
Example #3
0
    def from_distribution(dist: im.Distribution):
        record = Record()
        record.name = f"{dist.metadata['Name']}"
        record.version = dist.version
        record.url = f"{dist.metadata['Home-page']}"
        record.license = f"{dist.metadata['License']}"
        record.license_text = Record.get_license(dist.locate_file('.'))

        return record
Example #4
0
 def test_for_name_does_not_exist(self):
     with self.assertRaises(PackageNotFoundError):
         Distribution.from_name('does-not-exist')
Example #5
0
 def test_retrieves_version_of_self(self):
     dist = Distribution.from_name('distinfo-pkg')
     assert isinstance(dist.version, str)
     assert re.match(self.version_pattern, dist.version)
Example #6
0
 def test_find_local(self):
     dist = Distribution._local()
     assert dist.metadata['Name'] == 'local-pkg'
     assert dist.version == '2.0.1'
Example #7
0
 def test_distribution_at_str(self):
     dist_info_path = self.site_dir / 'distinfo_pkg-1.0.0.dist-info'
     dist = Distribution.at(str(dist_info_path))
     assert dist.version == '1.0.0'
Example #8
0
 def test_distribution_at_pathlib(self):
     """Demonstrate how to load metadata direct from a directory."""
     dist_info_path = self.site_dir / 'distinfo_pkg-1.0.0.dist-info'
     dist = Distribution.at(dist_info_path)
     assert dist.version == '1.0.0'
Example #9
0
 def test_find_distributions_specified_path(self):
     dists = Distribution.discover(path=[str(self.site_dir)])
     assert any(dist.metadata['Name'] == 'distinfo-pkg' for dist in dists)
Example #10
0
 def __init__(self, metadata, *args, **kwargs):
     Distribution.__init__(self, *args, **kwargs)
     self._data = metadata