2 from basetest
import BaseTest
3 import sys
, tempfile
, logging
6 sys
.path
.insert(0, '..')
8 from zeroinstall
.injector
import model
, gpg
, reader
11 foo_iface_uri
= 'http://foo'
12 bar_iface_uri
= 'http://localhost/bar'
14 logger
= logging
.getLogger()
16 class TestReader(BaseTest
):
20 stream
= tempfile
.TemporaryFile()
21 stream
.write(data
.thomas_key
)
23 gpg
.import_key(stream
)
25 def write_with_version(self
, version
):
26 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
28 """<?xml version="1.0" ?>
29 <interface last-modified="1110752708"
31 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
33 <summary>Foo</summary>
34 <description>Foo</description>
35 </interface>""" % (foo_iface_uri
, version
))
39 def testNoVersion(self
):
40 tmp
= self
.write_with_version('')
41 reader
.check_readable(foo_iface_uri
, tmp
.name
)
43 def testNewEnough(self
):
44 tmp
= self
.write_with_version('min-injector-version="0.19"')
45 reader
.check_readable(foo_iface_uri
, tmp
.name
)
48 tmp
= self
.write_with_version('min-injector-version="1000"')
50 reader
.check_readable(foo_iface_uri
, tmp
.name
)
51 except reader
.InvalidInterface
, ex
:
52 assert "1000" in str(ex
)
54 def testRequiresVersion(self
):
55 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
57 """<?xml version="1.0" ?>
58 <interface last-modified="1110752708"
60 xmlns="http://zero-install.sourceforge.net/2004/injector/interface"
61 xmlns:my='http://my/namespace'>
63 <summary>Foo</summary>
64 <description>Foo</description>
66 <requires interface='%s' my:foo='test'>
67 <version not-before='2.3.4' before='3.4.5'/>
69 <implementation id='sha1=123' version='1'/>
70 <requires interface='%s2'/>
72 </interface>""" % (foo_iface_uri
, bar_iface_uri
, bar_iface_uri
))
74 iface
= model
.Interface(foo_iface_uri
)
75 reader
.update(iface
, tmp
.name
, iface_cache
= self
.config
.iface_cache
)
76 feed
= self
.config
.iface_cache
.get_feed(foo_iface_uri
)
78 impl
= feed
.implementations
['sha1=123']
79 assert len(impl
.dependencies
) == 2
80 dep
= impl
.dependencies
[bar_iface_uri
]
81 assert len(dep
.restrictions
) == 1
82 res
= dep
.restrictions
[0]
83 assert res
.not_before
== [[2, 3, 4], 0]
84 assert res
.before
== [[3, 4, 5], 0]
85 dep2
= impl
.dependencies
[bar_iface_uri
+ '2']
86 assert len(dep2
.restrictions
) == 0
90 assert dep
.metadata
.get('http://my/namespace foo') == 'test'
91 assert dep
.metadata
.get('http://my/namespace food', None) == None
93 def testBindings(self
):
94 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
96 """<?xml version="1.0" ?>
97 <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
99 <summary>Foo</summary>
100 <description>Foo</description>
102 <requires interface='http://example.com/foo.xml'>
103 <environment name='PATH' insert='bin'/>
104 <environment name='PATH' insert='bin' mode='prepend'/>
105 <environment name='PATH' insert='bin' default='/bin' mode='append'/>
106 <environment name='PATH' insert='bin' mode='replace'/>
108 <implementation id='sha1=123' version='1'>
109 <environment name='SELF' insert='.' mode='replace'/>
114 iface
= model
.Interface(foo_iface_uri
)
115 reader
.update(iface
, tmp
.name
, local
= True, iface_cache
= self
.config
.iface_cache
)
117 feed
= self
.config
.iface_cache
.get_feed(foo_iface_uri
)
119 impl
= feed
.implementations
['sha1=123']
121 assert len(impl
.bindings
) == 1
122 self
.assertEquals(model
.EnvironmentBinding
.REPLACE
, impl
.bindings
[0].mode
)
124 assert len(impl
.requires
) == 1
125 dep
= impl
.requires
[0]
127 assert len(dep
.bindings
) == 4
128 for b
in dep
.bindings
:
129 self
.assertEquals('PATH', b
.name
)
130 self
.assertEquals('bin', b
.insert
)
131 self
.assertEquals(model
.EnvironmentBinding
.PREPEND
, dep
.bindings
[0].mode
)
132 self
.assertEquals(model
.EnvironmentBinding
.PREPEND
, dep
.bindings
[1].mode
)
133 self
.assertEquals(model
.EnvironmentBinding
.APPEND
, dep
.bindings
[2].mode
)
134 self
.assertEquals(model
.EnvironmentBinding
.REPLACE
, dep
.bindings
[3].mode
)
136 self
.assertEquals(None, dep
.bindings
[1].default
)
137 self
.assertEquals('/bin', dep
.bindings
[2].default
)
139 def testVersions(self
):
140 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
142 """<?xml version="1.0" ?>
145 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
147 <summary>Foo</summary>
148 <description>Foo</description>
149 <implementation id='sha1=123' version='1.0-rc3' version-modifier='-pre'/>
150 </interface>""" % foo_iface_uri
)
152 iface
= model
.Interface(foo_iface_uri
)
153 reader
.update(iface
, tmp
.name
, iface_cache
= self
.config
.iface_cache
)
154 feed
= self
.config
.iface_cache
.get_feed(foo_iface_uri
)
155 impl
= feed
.implementations
['sha1=123']
156 assert impl
.version
== [[1, 0], -1, [3], -2]
159 iface_cache
= self
.config
.iface_cache
160 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
162 """<?xml version="1.0" ?>
163 <interface last-modified="1110752708"
165 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
167 <summary>Foo</summary>
168 <description>Foo</description>
169 <group main='bin/sh' foo='foovalue' xmlns:bobpre='http://bob' bobpre:bob='bobvalue'>
170 <implementation id='sha1=123' version='1' bobpre:bob='newbobvalue'/>
171 <implementation id='sha1=124' version='2' main='next'/>
173 </interface>""" % foo_iface_uri
)
175 iface
= model
.Interface(foo_iface_uri
)
176 reader
.update(iface
, tmp
.name
, iface_cache
= self
.config
.iface_cache
)
178 feed
= iface_cache
.get_feed(foo_iface_uri
)
180 assert len(feed
.implementations
) == 2
182 assert feed
.implementations
['sha1=123'].metadata
['foo'] == 'foovalue'
183 assert feed
.implementations
['sha1=123'].metadata
['main'] == 'bin/sh'
184 assert feed
.implementations
['sha1=123'].metadata
['http://bob bob'] == 'newbobvalue'
186 assert feed
.implementations
['sha1=124'].metadata
['http://bob bob'] == 'bobvalue'
187 assert feed
.implementations
['sha1=124'].metadata
['main'] == 'next'
189 def testNative(self
):
190 iface_cache
= self
.config
.iface_cache
191 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
193 """<?xml version="1.0" ?>
194 <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
196 <summary>Foo</summary>
197 <description>Foo</description>
198 <package-implementation package='gimp'/>
199 <package-implementation package='python-bittorrent' foo='bar' main='/usr/bin/pbt'/>
203 iface
= model
.Interface(foo_iface_uri
)
204 reader
.update(iface
, tmp
.name
, True, iface_cache
= self
.config
.iface_cache
)
206 master_feed
= iface_cache
.get_feed(foo_iface_uri
)
207 assert len(master_feed
.implementations
) == 0
208 distro_feed_url
= master_feed
.get_distro_feed()
210 feed
= iface_cache
.get_feed(distro_feed_url
)
211 assert len(feed
.implementations
) == 1
213 impl
= feed
.implementations
['package:deb:python-bittorrent:3.4.2-10:*']
214 assert impl
.id == 'package:deb:python-bittorrent:3.4.2-10:*'
215 assert impl
.upstream_stability
== model
.packaged
216 assert impl
.user_stability
== None
217 assert impl
.requires
== []
218 assert impl
.main
== '/usr/bin/pbt'
219 assert impl
.metadata
['foo'] == 'bar'
220 assert impl
.feed
== feed
223 tmp
= tempfile
.NamedTemporaryFile(prefix
= 'test-')
225 """<?xml version="1.0" ?>
226 <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
228 <summary>Foo</summary>
229 <description>Foo</description>
230 <feed langs='fr en_GB' src='http://localhost/feed.xml'/>
232 <group langs='fr en_GB'>
233 <implementation id='sha1=124' version='2' langs='fr'/>
234 <implementation id='sha1=234' version='2'/>
236 <implementation id='sha1=345' version='2'/>
241 feed
= reader
.load_feed(tmp
.name
, local
= True)
243 assert len(feed
.implementations
) == 3
244 assert len(feed
.feeds
) == 1, feed
.feeds
246 self
.assertEquals('fr en_GB', feed
.feeds
[0].langs
)
248 self
.assertEquals('fr', feed
.implementations
['sha1=124'].langs
)
249 self
.assertEquals('fr en_GB', feed
.implementations
['sha1=234'].langs
)
250 self
.assertEquals('', feed
.implementations
['sha1=345'].langs
)
252 if __name__
== '__main__':