def testFeeds(self): iface = model.Interface('http://test/test') main_feed = model.ZeroInstallFeed(test_feed, local_path='/Hello') self.config.iface_cache._feeds[iface.uri] = main_feed iface.stability_policy = model.developer main_feed.last_checked = 100 iface.extra_feeds.append(model.Feed('http://sys-feed', None, False)) iface.extra_feeds.append( model.Feed('http://user-feed', 'Linux-*', True)) writer.save_interface(iface) writer.save_feed(main_feed) iface = model.Interface('http://test/test') self.assertEquals(None, iface.stability_policy) main_feed = model.ZeroInstallFeed(test_feed, local_path='/Hello') self.config.iface_cache._feeds[iface.uri] = main_feed reader.update_user_overrides(iface) reader.update_user_feed_overrides(main_feed) self.assertEquals(model.developer, iface.stability_policy) self.assertEquals(100, main_feed.last_checked) self.assertEquals("[<Feed from http://user-feed>]", str(iface.extra_feeds)) feed = iface.extra_feeds[0] self.assertEquals('http://user-feed', feed.uri) self.assertEquals('Linux', feed.os) self.assertEquals(None, feed.machine)
def testStoreNothing(self): iface = model.Interface('http://test/test') writer.save_interface(iface) iface = model.Interface('http://test/test') self.assertEquals(None, iface.stability_policy) reader.update_user_overrides(iface) feed = self.config.iface_cache.get_feed(iface.uri) self.assertEquals(None, feed)
def testNative(self): iface_cache = self.config.iface_cache tmp = tempfile.NamedTemporaryFile(mode='wt', prefix='test-') tmp.write("""<?xml version="1.0" ?> <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface"> <name>Foo</name> <summary>Foo</summary> <description>Foo</description> <package-implementation package='gimp'/> <package-implementation package='python-bittorrent' foo='bar' main='/usr/bin/pbt'/> </interface>""") tmp.flush() iface = model.Interface(foo_iface_uri) reader.update(iface, tmp.name, True, iface_cache=self.config.iface_cache) master_feed = iface_cache.get_feed(foo_iface_uri) assert len(master_feed.implementations) == 0 distro_feed_url = master_feed.get_distro_feed() feed = iface_cache.get_feed(distro_feed_url) assert len(feed.implementations) == 1 impl = feed.implementations['package:deb:python-bittorrent:3.4.2-10:*'] assert impl.id == 'package:deb:python-bittorrent:3.4.2-10:*' assert impl.upstream_stability == model.packaged assert impl.user_stability == None assert impl.requires == [] assert impl.main == '/usr/bin/pbt' assert impl.metadata['foo'] == 'bar' assert impl.feed == feed
def testAttrs(self): iface_cache = self.config.iface_cache tmp = tempfile.NamedTemporaryFile(mode='wt', prefix='test-') tmp.write("""<?xml version="1.0" ?> <interface last-modified="1110752708" uri="%s" xmlns="http://zero-install.sourceforge.net/2004/injector/interface"> <name>Foo</name> <summary>Foo</summary> <description>Foo</description> <group main='bin/sh' foo='foovalue' xmlns:bobpre='http://bob' bobpre:bob='bobvalue'> <implementation id='sha1=123' version='1' bobpre:bob='newbobvalue'/> <implementation id='sha1=124' version='2' main='next'/> </group> </interface>""" % foo_iface_uri) tmp.flush() iface = model.Interface(foo_iface_uri) reader.update(iface, tmp.name, iface_cache=self.config.iface_cache) feed = iface_cache.get_feed(foo_iface_uri) assert len(feed.implementations) == 2 assert feed.implementations['sha1=123'].metadata['foo'] == 'foovalue' assert feed.implementations['sha1=123'].metadata['main'] == 'bin/sh' assert feed.implementations['sha1=123'].metadata[ 'http://bob bob'] == 'newbobvalue' assert feed.implementations['sha1=124'].metadata[ 'http://bob bob'] == 'bobvalue' assert feed.implementations['sha1=124'].metadata['main'] == 'next'
def testBindings(self): tmp = tempfile.NamedTemporaryFile(prefix='test-') tmp.write("""<?xml version="1.0" ?> <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface"> <name>Foo</name> <summary>Foo</summary> <description>Foo</description> <group> <requires interface='http://example.com/foo.xml'> <environment name='PATH' insert='bin'/> <environment name='PATH' insert='bin' mode='prepend'/> <environment name='PATH' insert='bin' default='/bin' mode='append'/> <environment name='PATH' insert='bin' mode='replace'/> <environment name='PATH' insert='bin' separator=',' /> </requires> <implementation id='sha1=123' version='1'> <environment name='SELF' insert='.' mode='replace'/> </implementation> </group> </interface>""") tmp.flush() iface = model.Interface(foo_iface_uri) reader.update(iface, tmp.name, local=True, iface_cache=self.config.iface_cache) feed = self.config.iface_cache.get_feed(foo_iface_uri) impl = feed.implementations['sha1=123'] assert len(impl.bindings) == 1 self.assertEquals(model.EnvironmentBinding.REPLACE, impl.bindings[0].mode) assert len(impl.requires) == 1 dep = impl.requires[0] assert len(dep.bindings) == 5 for b in dep.bindings: self.assertEquals('PATH', b.name) self.assertEquals('bin', b.insert) self.assertEquals(model.EnvironmentBinding.PREPEND, dep.bindings[0].mode) self.assertEquals(model.EnvironmentBinding.PREPEND, dep.bindings[1].mode) self.assertEquals(model.EnvironmentBinding.APPEND, dep.bindings[2].mode) self.assertEquals(model.EnvironmentBinding.REPLACE, dep.bindings[3].mode) self.assertEquals(model.EnvironmentBinding.PREPEND, dep.bindings[4].mode) self.assertEquals(os.path.join('/impl', 'bin:current'), dep.bindings[0].get_value('/impl', 'current')) self.assertEquals(os.path.join('/impl', 'bin,current'), dep.bindings[4].get_value('/impl', 'current')) self.assertEquals(None, dep.bindings[1].default) self.assertEquals('/bin', dep.bindings[2].default)
def complete(completion, args, cword): """@type completion: L{zeroinstall.cmd._Completion} @type args: [str] @type cword: int""" if len(args) != 1: return iface_cache = completion.config.iface_cache for uri in iface_cache.list_all_interfaces(): dummy = model.Interface(uri) reader.update_user_overrides(dummy) if dummy.extra_feeds: completion.add_filtered(uri)
def complete(completion, args, cword): """@type completion: L{zeroinstall.cmd._Completion} @type args: [str] @type cword: int""" if cword > 1: return if cword == 0: list_feeds.complete(completion, args[:1], 1) # Or it could be a feed directly completion.expand_files() if cword == 1: # With two arguments, we can only remove a feed that is registered dummy = model.Interface(args[0]) reader.update_user_overrides(dummy) for feed in dummy.extra_feeds: completion.add_filtered(feed.uri)
def testVersions(self): tmp = tempfile.NamedTemporaryFile(prefix='test-') tmp.write("""<?xml version="1.0" ?> <interface uri="%s" xmlns="http://zero-install.sourceforge.net/2004/injector/interface"> <name>Foo</name> <summary>Foo</summary> <description>Foo</description> <implementation id='sha1=123' version='1.0-rc3' version-modifier='-pre'/> </interface>""" % foo_iface_uri) tmp.flush() iface = model.Interface(foo_iface_uri) reader.update(iface, tmp.name, iface_cache=self.config.iface_cache) feed = self.config.iface_cache.get_feed(foo_iface_uri) impl = feed.implementations['sha1=123'] assert impl.version == [[1, 0], -1, [3], -2]
def testImpl(self): i = model.Interface('http://foo') a = model.ZeroInstallImplementation(i, 'foo', None) assert a.id == 'foo' assert a.size == a.version == a.user_stability == None assert a.arch == a.upstream_stability == None assert a.dependencies == {} assert a.download_sources == [] assert a.get_stability() is model.testing a.upstream_stability = model.stable assert a.get_stability() is model.stable a.user_stability = model.buggy assert a.get_stability() is model.buggy a.version = model.parse_version('1.2.3') self.assertEquals('1.2.3', a.get_version()) a.version = model.parse_version('1.2.3-rc2-post') self.assertEquals('1.2.3-rc2-post', a.get_version()) assert str(a) == 'foo' b = model.ZeroInstallImplementation(i, 'foo', None) b.version = [1,2,1] assert b > a
def testRequiresVersion(self): tmp = tempfile.NamedTemporaryFile(mode='wt', prefix='test-') tmp.write("""<?xml version="1.0" ?> <interface last-modified="1110752708" uri="%s" xmlns="http://zero-install.sourceforge.net/2004/injector/interface" xmlns:my='http://my/namespace'> <name>Foo</name> <summary>Foo</summary> <description>Foo</description> <group> <requires interface='%s' my:foo='test'> <version not-before='2.3.4' before='3.4.5'/> </requires> <implementation id='sha1=123' version='1'/> <requires interface='%s2'/> </group> </interface>""" % (foo_iface_uri, bar_iface_uri, bar_iface_uri)) tmp.flush() iface = model.Interface(foo_iface_uri) reader.update(iface, tmp.name, iface_cache=self.config.iface_cache) feed = self.config.iface_cache.get_feed(foo_iface_uri) impl = feed.implementations['sha1=123'] assert len(impl.dependencies) == 2 dep = impl.dependencies[bar_iface_uri] assert len(dep.restrictions) == 1 res = dep.restrictions[0] assert res.not_before == [[2, 3, 4], 0] assert res.before == [[3, 4, 5], 0] dep2 = impl.dependencies[bar_iface_uri + '2'] assert len(dep2.restrictions) == 0 str(dep) str(dep2) assert dep.metadata.get('http://my/namespace foo') == 'test' assert dep.metadata.get('http://my/namespace food', None) == None
def get_interface(self, uri): if uri not in self.interfaces: iface = model.Interface(uri) self.interfaces[uri] = iface return self.interfaces[uri]
def testInterface(self): i = model.Interface('http://foo') self.assertEqual('(foo)', i.get_name()) feed = model.ZeroInstallFeed(empty_feed, local_path='/foo') self.assertEqual('Empty', feed.get_name()) repr(i)
def testBadInterface(self): try: model.Interface('foo') assert 0 except model.SafeException: pass
def testStabPolicy(self): i = model.Interface('http://foo') self.assertEqual(None, i.stability_policy) i.set_stability_policy(model.buggy) self.assertEqual(model.buggy, i.stability_policy)