def env(self, tmpdir): """ Create a package environment, similar to a virtualenv, in which packages are installed. """ class Environment(str): pass env = Environment(tmpdir) tmpdir.chmod(stat.S_IRWXU) subs = 'home', 'lib', 'scripts', 'data', 'egg-base' env.paths = dict((dirname, str(tmpdir / dirname)) for dirname in subs) list(map(os.mkdir, env.paths.values())) return env
def env(self, tmpdir): """ Create a package environment, similar to a virtualenv, in which packages are installed. """ class Environment(str): pass env = Environment(tmpdir) tmpdir.chmod(stat.S_IRWXU) subs = 'home', 'lib', 'scripts', 'data', 'egg-base' env.paths = dict( (dirname, str(tmpdir / dirname)) for dirname in subs ) list(map(os.mkdir, env.paths.values())) return env
def testResolve(self): ad = pkg_resources.Environment([]) ws = WorkingSet([]) # Resolving no requirements -> nothing to install assert list(ws.resolve([], ad)) == [] # Request something not in the collection -> DistributionNotFound with pytest.raises(pkg_resources.DistributionNotFound): ws.resolve(parse_requirements("Foo"), ad) Foo = Distribution.from_filename( "/foo_dir/Foo-1.2.egg", metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0")) ) ad.add(Foo) ad.add(Distribution.from_filename("Foo-0.9.egg")) # Request thing(s) that are available -> list to activate for i in range(3): targets = list(ws.resolve(parse_requirements("Foo"), ad)) assert targets == [Foo] list(map(ws.add, targets)) with pytest.raises(VersionConflict): ws.resolve(parse_requirements("Foo==0.9"), ad) ws = WorkingSet([]) # reset # Request an extra that causes an unresolved dependency for "Baz" with pytest.raises(pkg_resources.DistributionNotFound): ws.resolve(parse_requirements("Foo[bar]"), ad) Baz = Distribution.from_filename( "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo")) ) ad.add(Baz) # Activation list now includes resolved dependency assert ( list(ws.resolve(parse_requirements("Foo[bar]"), ad)) == [Foo, Baz] ) # Requests for conflicting versions produce VersionConflict 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' assert vc.value.report() == msg