Commit 22370657 authored by PJ Eby's avatar PJ Eby

Add tests for AvailableDistributions().resolve(). This effectively

completes the core dependency resolution engine; all we need now is a way
to turn sys.path entries into "distribution sources" that can list
Distribution objects for inclusion in an instance of
AvailableDistributions, and the 'require("SomePkg>=2.7")' API will be
usable.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041009
parent 489117c3
......@@ -250,12 +250,12 @@ class AvailableDistributions(object):
if path is None:
path = sys.path
requirements = list(requirements)[::1] # set up the stack
requirements = list(requirements)[::-1] # set up the stack
processed = {} # set of processed requirements
best = {} # key -> dist
to_install = []
while requirements:
req = requirements.pop()
if req in processed:
# Ignore cyclic or redundant dependencies
......@@ -268,15 +268,16 @@ class AvailableDistributions(object):
dist = best[req.key] = self.best_match(req,path)
if dist is None:
raise DistributionNotFound(req) # XXX put more info here
to_install.append(dist)
elif dist not in requirement:
elif dist not in req:
# Oops, the "best" so far conflicts with a dependency
raise VersionConflict(req,dist) # XXX put more info here
requirements.extend(dist.depends(req.options)[::-1])
processed[req] = True
return best.values() # return list of distros to install
return to_install # return list of distros to install
def obtain(self, requirement):
......@@ -284,7 +285,6 @@ class AvailableDistributions(object):
return None # override this in subclasses
class ResourceManager:
"""Manage resource extraction and packages"""
......@@ -418,7 +418,6 @@ def require(*requirements):
* get_distro_source() isn't implemented
* Distribution.install_on() isn't implemented
* AvailableDistributions.resolve() is untested
* AvailableDistributions.scan() is untested
There may be other things missing as well, but this definitely won't work
......@@ -448,6 +447,7 @@ def require(*requirements):
class DefaultProvider:
"""Provides access to package resources in the filesystem"""
......
......@@ -121,6 +121,47 @@ class DistroTests(TestCase):
self.checkDepends(self.distDepends(v), v)
def testResolve(self):
ad = AvailableDistributions([])
# Resolving no requirements -> nothing to install
self.assertEqual( list(ad.resolve([],[])), [] )
# Request something not in the collection -> DistributionNotFound
self.assertRaises(
DistributionNotFound, ad.resolve, parse_requirements("Foo"), []
)
Foo = Distribution.from_filename(
"/foo_dir/Foo-1.2.egg",
metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
)
ad.add(Foo)
# Request thing(s) that are available -> list to install
self.assertEqual(
list(ad.resolve(parse_requirements("Foo"),[])), [Foo]
)
# Request an option that causes an unresolved dependency for "Baz"
self.assertRaises(
DistributionNotFound, ad.resolve,parse_requirements("Foo[bar]"),[]
)
Baz = Distribution.from_filename(
"/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
)
ad.add(Baz)
# Install list now includes resolved dependency
self.assertEqual(
list(ad.resolve(parse_requirements("Foo[bar]"),[])), [Foo,Baz]
)
# Requests for conflicting versions produce VersionConflict
self.assertRaises(
VersionConflict,
ad.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), []
)
def testDistroDependsOptions(self):
d = self.distDepends("""
Twisted>=1.5
......
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