1 #!/usr/bin/env python2.5
2 from basetest
import BaseTest
3 from StringIO
import StringIO
7 sys
.path
.insert(0, '..')
8 from zeroinstall
.injector
import selections
, model
, reader
, policy
, iface_cache
, namespaces
, qdom
10 class TestSelections(BaseTest
):
11 def testSelections(self
):
12 p
= policy
.Policy('http://foo/Source.xml', src
= True)
13 source
= iface_cache
.iface_cache
.get_interface('http://foo/Source.xml')
14 compiler
= iface_cache
.iface_cache
.get_interface('http://foo/Compiler.xml')
15 reader
.update(source
, 'Source.xml')
16 reader
.update(compiler
, 'Compiler.xml')
19 p
.network_use
= model
.network_full
21 #logging.getLogger().setLevel(logging.DEBUG)
25 self
.assertEquals('http://foo/Source.xml', s
.interface
)
26 self
.assertEquals(2, len(s
.selections
))
28 sels
= [(sel
.interface
, sel
) for sel
in s
.selections
.values()]
30 sels
= [sel
for uri
,sel
in sels
]
32 self
.assertEquals('http://foo/Compiler.xml', sels
[0].interface
)
33 self
.assertEquals('http://foo/Source.xml', sels
[1].interface
)
35 self
.assertEquals("sha1=345", sels
[0].id)
36 self
.assertEquals("1.0", sels
[0].version
)
38 self
.assertEquals('sha1=234', sels
[1].id)
39 self
.assertEquals("1.0", sels
[1].version
)
40 self
.assertEquals("bar", sels
[1].attrs
['http://namespace foo'])
41 self
.assertEquals("1.0", sels
[1].attrs
['version'])
42 assert 'version-modifier' not in sels
[1].attrs
44 self
.assertEquals(0, len(sels
[0].bindings
))
45 self
.assertEquals(0, len(sels
[0].dependencies
))
47 self
.assertEquals(1, len(sels
[1].bindings
))
48 self
.assertEquals('.', sels
[1].bindings
[0].insert
)
50 self
.assertEquals(1, len(sels
[1].dependencies
))
51 dep
= sels
[1].dependencies
[0]
52 self
.assertEquals('http://foo/Compiler.xml', dep
.interface
)
53 self
.assertEquals(1, len(dep
.bindings
))
55 s1
= selections
.Selections(p
)
56 s1
.selections
['http://foo/Source.xml'].attrs
['http://namespace foo'] = 'bar'
59 xml
= s1
.toDOM().toxml("utf-8")
60 root
= qdom
.parse(StringIO(xml
))
61 self
.assertEquals(namespaces
.XMLNS_IFACE
, root
.uri
)
63 s2
= selections
.Selections(root
)
66 suite
= unittest
.makeSuite(TestSelections
)
67 if __name__
== '__main__':