1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
"""Test .dist-info style distributions.
"""
from __future__ import unicode_literals
from setuptools.extern.six.moves import map
import pytest
import pkg_resources
from .textwrap import DALS
class TestDistInfo:
metadata_base = DALS("""
Metadata-Version: 1.2
Requires-Dist: splort (==4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
""")
@classmethod
def build_metadata(cls, **kwargs):
lines = (
'{key}: {value}\n'.format(**locals())
for key, value in kwargs.items()
)
return cls.metadata_base + ''.join(lines)
@pytest.fixture
def metadata(self, tmpdir):
dist_info_name = 'VersionedDistribution-2.718.dist-info'
versioned = tmpdir / dist_info_name
versioned.mkdir()
filename = versioned / 'METADATA'
content = self.build_metadata(
Name='VersionedDistribution',
)
filename.write_text(content, encoding='utf-8')
dist_info_name = 'UnversionedDistribution.dist-info'
unversioned = tmpdir / dist_info_name
unversioned.mkdir()
filename = unversioned / 'METADATA'
content = self.build_metadata(
Name='UnversionedDistribution',
Version='0.3',
)
filename.write_text(content, encoding='utf-8')
return str(tmpdir)
def test_distinfo(self, metadata):
dists = dict(
(d.project_name, d)
for d in pkg_resources.find_distributions(metadata)
)
assert len(dists) == 2, dists
unversioned = dists['UnversionedDistribution']
versioned = dists['VersionedDistribution']
assert versioned.version == '2.718' # from filename
assert unversioned.version == '0.3' # from METADATA
def test_conditional_dependencies(self, metadata):
specs = 'splort==4', 'quux>=1.1'
requires = list(map(pkg_resources.Requirement.parse, specs))
for d in pkg_resources.find_distributions(metadata):
assert d.requires() == requires[:1]
assert d.requires(extras=('baz',)) == [
requires[0],
pkg_resources.Requirement.parse('quux>=1.1;extra=="baz"'),
]
assert d.extras == ['baz']
|