Commit 23d5e4a8 authored by Jason R. Coombs's avatar Jason R. Coombs

Test the report method

parent 880ccea0
......@@ -317,8 +317,34 @@ class ResolutionError(Exception):
def __repr__(self):
return self.__class__.__name__+repr(self.args)
class VersionConflict(ResolutionError):
"""An already-installed version conflicts with the requested version"""
"""
An already-installed version conflicts with the requested version.
Should be initialized with the installed Distribution, the requested
Requirement, and optionally a list of dists that required the installed
Distribution.
"""
@property
def dist(self):
return self.args[0]
@property
def req(self):
return self.args[1]
@property
def required_by(self):
return self.args[2] if len(self.args) > 2 else []
def report(self):
template = "{self.dist} is installed but {self.req} is required"
if self.required_by:
template += " by {self.required_by}"
return template.format(**locals())
class DistributionNotFound(ResolutionError):
"""A requested distribution was not found"""
......@@ -763,9 +789,8 @@ class WorkingSet(object):
to_activate.append(dist)
if dist not in req:
# Oops, the "best" so far conflicts with a dependency
tmpl = "%s is installed but %s is required by %s"
args = dist, req, list(required_by.get(req, []))
raise VersionConflict(tmpl % args)
dependent_req = list(required_by.get(req, []))
raise VersionConflict(dist, req, dependent_req)
# push the new requirements onto the stack
new_requirements = dist.requires(req.extras)[::-1]
......
......@@ -175,8 +175,8 @@ class TestDistro:
with pytest.raises(VersionConflict) as vc:
ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
msg = 'Foo 0.9 is installed but Foo==1.2 is required by []'
assert str(vc).endswith(msg)
msg = 'Foo 0.9 is installed but Foo==1.2 is required'
assert vc.value.report() == msg
def testDistroDependsOptions(self):
d = self.distRequires("""
......@@ -218,7 +218,7 @@ class TestWorkingSet:
ws.find(req)
msg = 'Foo 1.2 is installed but Foo<1.2 is required'
assert str(vc).endswith(msg)
assert vc.value.report() == msg
class TestEntryPoints:
......
......@@ -703,10 +703,7 @@ Please make the appropriate changes for your system and try again.
"Could not find required distribution %s" % e.args
)
except VersionConflict as e:
raise DistutilsError(
"Installed distribution %s conflicts with requirement %s"
% e.args
)
raise DistutilsError(e.report())
if self.always_copy or self.always_copy_from:
# Force all the relevant distros to be copied or activated
for dist in distros:
......
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