Commit b73bf20c authored by Daniel Holth's avatar Daniel Holth

test .dist-info distributions

--HG--
branch : distribute
extra : rebase_source : ea6870d73aa69f2deacc50beb2e257d3c21073e4
parent 0d5901c0
...@@ -2514,21 +2514,7 @@ class DistInfoDistribution(Distribution): ...@@ -2514,21 +2514,7 @@ class DistInfoDistribution(Distribution):
dm[extra] = list(set(reqs_for_extra(extra)) - common) dm[extra] = list(set(reqs_for_extra(extra)) - common)
return dm return dm
def requires(self,extras=()):
"""List of Requirements needed for this distro if `extras` are used"""
dm = self._dep_map
deps = []
deps.extend(dm.get(None,()))
for ext in extras:
try:
deps.extend(dm[safe_extra(ext)])
except KeyError:
raise UnknownExtra(
"%s has no such extra feature %r" % (self, ext)
)
return deps
_distributionImpl = {'.egg': Distribution, _distributionImpl = {'.egg': Distribution,
'.egg-info': Distribution, '.egg-info': Distribution,
......
"""Test .dist-info style distributions.
"""
import os, shutil, tempfile, unittest
import pkg_resources
from pkg_resources import Requirement
class TestDistInfo(unittest.TestCase):
def test_distinfo(self):
dists = {}
for d in pkg_resources.find_distributions(self.tmpdir):
dists[d.project_name] = d
unversioned = dists['UnversionedDistribution']
versioned = dists['VersionedDistribution']
assert versioned.version == '2.718' # from filename
assert unversioned.version == '0.3' # from METADATA
requires = [Requirement.parse('splort==4'),
Requirement.parse('quux>=1.1')]
for d in (unversioned, versioned):
self.assertEquals(d.requires(), requires[:1])
self.assertEquals(d.requires(extras=('baz',)), requires)
self.assertEquals(d.extras, ['baz'])
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
versioned = os.path.join(self.tmpdir,
'VersionedDistribution-2.718.dist-info')
os.mkdir(versioned)
open(os.path.join(versioned, 'METADATA'), 'w+').write(
"""Metadata-Version: 1.2
Name: VersionedDistribution
Requires-Dist: splort (4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
""")
unversioned = os.path.join(self.tmpdir,
'UnversionedDistribution.dist-info')
os.mkdir(unversioned)
open(os.path.join(unversioned, 'METADATA'), 'w+').write(
"""Metadata-Version: 1.2
Name: UnversionedDistribution
Version: 0.3
Requires-Dist: splort (==4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
""")
def tearDown(self):
shutil.rmtree(self.tmpdir)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment