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 mydir
= os
.path
.dirname(os
.path
.abspath(__file__
))
12 class TestSelections(BaseTest
):
13 def testSelections(self
):
14 p
= policy
.Policy('http://foo/Source.xml', src
= True)
15 source
= iface_cache
.iface_cache
.get_interface('http://foo/Source.xml')
16 compiler
= iface_cache
.iface_cache
.get_interface('http://foo/Compiler.xml')
17 reader
.update(source
, 'Source.xml')
18 reader
.update(compiler
, 'Compiler.xml')
21 p
.network_use
= model
.network_full
23 #logging.getLogger().setLevel(logging.DEBUG)
27 self
.assertEquals('http://foo/Source.xml', s
.interface
)
28 self
.assertEquals(2, len(s
.selections
))
30 sels
= [(sel
.interface
, sel
) for sel
in s
.selections
.values()]
32 sels
= [sel
for uri
,sel
in sels
]
34 self
.assertEquals('http://foo/Compiler.xml', sels
[0].interface
)
35 self
.assertEquals('http://foo/Source.xml', sels
[1].interface
)
37 self
.assertEquals("sha1=345", sels
[0].id)
38 self
.assertEquals("1.0", sels
[0].version
)
40 self
.assertEquals('sha1=234', sels
[1].id)
41 self
.assertEquals("1.0", sels
[1].version
)
42 self
.assertEquals("bar", sels
[1].attrs
['http://namespace foo'])
43 self
.assertEquals("1.0", sels
[1].attrs
['version'])
44 assert 'version-modifier' not in sels
[1].attrs
46 self
.assertEquals(0, len(sels
[0].bindings
))
47 self
.assertEquals(0, len(sels
[0].dependencies
))
49 self
.assertEquals(1, len(sels
[1].bindings
))
50 self
.assertEquals('.', sels
[1].bindings
[0].insert
)
52 self
.assertEquals(1, len(sels
[1].dependencies
))
53 dep
= sels
[1].dependencies
[0]
54 self
.assertEquals('http://foo/Compiler.xml', dep
.interface
)
55 self
.assertEquals(1, len(dep
.bindings
))
56 self
.assertEquals(["sha1=345"], sels
[0].digests
)
58 s1
= selections
.Selections(p
)
59 s1
.selections
['http://foo/Source.xml'].attrs
['http://namespace foo'] = 'bar'
62 xml
= s1
.toDOM().toxml("utf-8")
63 root
= qdom
.parse(StringIO(xml
))
64 self
.assertEquals(namespaces
.XMLNS_IFACE
, root
.uri
)
66 s2
= selections
.Selections(root
)
69 def testLocalPath(self
):
70 iface
= os
.path
.join(mydir
, "Local.xml")
71 p
= policy
.Policy(iface
)
73 s1
= selections
.Selections(p
)
74 xml
= s1
.toDOM().toxml("utf-8")
75 root
= qdom
.parse(StringIO(xml
))
76 s2
= selections
.Selections(root
)
77 local_path
= s2
.selections
[iface
].local_path
78 assert os
.path
.isdir(local_path
), local_path
80 suite
= unittest
.makeSuite(TestSelections
)
81 if __name__
== '__main__':