1 #!/usr/bin/env python2.3
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
5 from StringIO
import StringIO
7 sys
.path
.insert(0, '..')
8 from zeroinstall
.injector
import model
, qdom
10 class TestModel(BaseTest
):
12 assert model
.network_offline
in model
.network_levels
13 assert model
.network_minimal
in model
.network_levels
14 assert model
.network_full
in model
.network_levels
16 def testStabilities(self
):
17 assert 'insecure' in model
.stability_levels
18 assert 'buggy' in model
.stability_levels
19 assert 'developer' in model
.stability_levels
20 assert 'testing' in model
.stability_levels
21 assert 'stable' in model
.stability_levels
22 assert 'preferred' in model
.stability_levels
26 self
.assertEquals("", model
.escape(""))
27 self
.assertEquals("hello", model
.escape("hello"))
28 self
.assertEquals("%20", model
.escape(" "))
29 self
.assertEquals("file%3a%2f%2ffoo%7ebar",
30 model
.escape("file://foo~bar"))
31 self
.assertEquals("file%3a%2f%2ffoo%25bar",
32 model
.escape("file://foo%bar"))
34 def testUnescape(self
):
35 self
.assertEquals("", model
.unescape(""))
36 self
.assertEquals("hello", model
.unescape("hello"))
37 self
.assertEquals(" ", model
.unescape("%20"))
38 self
.assertEquals("file://foo~bar",
39 model
.unescape("file%3a%2f%2ffoo%7ebar"))
40 self
.assertEquals("file://foo%bar",
41 model
.unescape("file%3a%2f%2ffoo%25bar"))
43 def testBadInterface(self
):
45 model
.Interface('foo')
47 except model
.SafeException
:
50 def testInterface(self
):
51 i
= model
.Interface('http://foo')
52 self
.assertEquals('(foo)', i
.get_name())
55 def testMetadata(self
):
56 i
= model
.Interface('http://foo')
57 e
= qdom
.parse(StringIO('<ns:b xmlns:ns="a" foo="bar"/>'))
59 assert i
.get_metadata('a', 'b') == [e
]
60 assert i
.get_metadata('b', 'b') == []
61 assert i
.get_metadata('a', 'a') == []
62 assert e
.getAttribute('foo') == 'bar'
64 def testStabPolicy(self
):
65 i
= model
.Interface('http://foo')
66 self
.assertEquals(None, i
.stability_policy
)
67 i
.set_stability_policy(model
.buggy
)
68 self
.assertEquals(model
.buggy
, i
.stability_policy
)
70 def testGetImpl(self
):
71 i
= model
.Interface('http://foo')
78 assert isinstance(a
, model
.Implementation
)
81 i
= model
.Interface('http://foo')
82 a
= model
.Implementation(i
, 'foo')
84 assert a
.size
== a
.version
== a
.user_stability
== None
85 assert a
.arch
== a
.upstream_stability
== None
86 assert a
.dependencies
== {}
87 assert a
.download_sources
== []
88 assert a
.get_stability() is model
.testing
89 a
.upstream_stability
= model
.stable
90 assert a
.get_stability() is model
.stable
91 a
.user_stability
= model
.buggy
92 assert a
.get_stability() is model
.buggy
93 a
.version
= model
.parse_version('1.2.3')
94 self
.assertEquals('1.2.3', a
.get_version())
95 a
.version
= model
.parse_version('1.2.3-rc2-post')
96 self
.assertEquals('1.2.3-rc2-post', a
.get_version())
97 assert str(a
) == 'foo'
99 b
= model
.Implementation(i
, 'foo')
103 def testDownloadSource(self
):
104 i
= model
.Interface('http://foo')
105 a
= model
.Implementation(i
, 'foo')
106 a
.add_download_source('ftp://foo', 1024, None)
107 a
.add_download_source('ftp://foo.tgz', 1025, 'foo')
108 assert a
.download_sources
[0].url
== 'ftp://foo'
109 assert a
.download_sources
[0].size
== 1024
110 assert a
.download_sources
[0].extract
== None
111 assert a
.interface
is i
113 def testEnvBind(self
):
114 a
= model
.EnvironmentBinding('PYTHONPATH', 'path')
115 assert a
.name
== 'PYTHONPATH'
116 assert a
.insert
== 'path'
120 b
= model
.Dependency('http://foo')
121 assert not b
.restrictions
122 assert not b
.bindings
126 f
= model
.Feed('http://feed', arch
= None, user_override
= False)
127 assert f
.uri
== 'http://feed'
129 assert f
.machine
== None
130 assert f
.arch
== None
131 assert f
.user_override
== False
133 f
= model
.Feed('http://feed', arch
= 'Linux-*', user_override
= True)
134 assert f
.uri
== 'http://feed'
135 assert f
.os
== 'Linux'
136 assert f
.machine
== None
137 assert f
.arch
== 'Linux-*'
138 assert f
.user_override
== True
140 f
= model
.Feed('http://feed', arch
= '*-i386', user_override
= True)
141 assert f
.uri
== 'http://feed'
143 assert f
.machine
== 'i386'
144 assert f
.arch
== '*-i386'
145 assert f
.user_override
== True
146 assert str(f
).startswith('<Feed from')
149 f
= model
.Feed('http://feed', arch
= 'i386', user_override
= True)
151 except model
.SafeException
, ex
:
152 assert 'Malformed arch' in str(ex
)
154 def testCanonical(self
):
155 self
.assertEquals('http://foo',
156 model
.canonical_iface_uri('http://foo'))
158 model
.canonical_iface_uri('bad-name')
160 except model
.SafeException
, ex
:
161 assert 'Bad interface name' in str(ex
)
163 def testVersions(self
):
165 parsed
= model
.parse_version(v
)
166 assert model
.format_version(parsed
) == v
169 assert pv('1.0') > pv('0.9')
170 assert pv('1.0') > pv('1')
171 assert pv('1.0') == pv('1.0')
172 assert pv('0.9.9') < pv('1.0')
178 except model
.SafeException
, ex
:
186 assert pv('1') == [[1], 0]
187 assert pv('1.0') == [[1,0], 0]
188 assert pv('1.0-pre5') == [[1,0], -2, [5], 0]
189 assert pv('1.0-rc5') == [[1,0], -1, [5], 0]
190 assert pv('1.0-5') == [[1,0], 0, [5], 0]
191 assert pv('1.0-post5') == [[1,0], 1, [5], 0]
192 assert pv('1.0-post') == [[1,0], 1]
193 assert pv('1-rc2.0-pre2-post') == [[1], -1, [2,0], -2, [2], 1]
194 assert pv('1-rc2.0-pre-post') == [[1], -1, [2,0], -2, [], 1]
196 assert pv('1.0-0') > pv('1.0')
197 assert pv('1.0-1') > pv('1.0-0')
198 assert pv('1.0-0') < pv('1.0-1')
200 assert pv('1.0-pre99') > pv('1.0-pre1')
201 assert pv('1.0-pre99') < pv('1.0-rc1')
202 assert pv('1.0-rc1') < pv('1.0')
203 assert pv('1.0') < pv('1.0-0')
204 assert pv('1.0-0') < pv('1.0-post')
205 assert pv('2.1.9-pre-1') > pv('2.1.9-pre')
207 assert pv('2-post999') < pv('3-pre1')
209 suite
= unittest
.makeSuite(TestModel
)
210 if __name__
== '__main__':
211 sys
.argv
.append('-v')