Better exception handling in GUI.
[zeroinstall/zeroinstall-rsl.git] / tests / testselections.py
blob023840f4527b183049929bbd3dcbb176cd827bab
1 #!/usr/bin/env python2.4
2 from basetest import BaseTest
3 from StringIO import StringIO
4 import sys
5 import unittest
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')
18 p.freshness = 0
19 p.network_use = model.network_full
20 #import logging
21 #logging.getLogger().setLevel(logging.DEBUG)
22 p.recalculate()
24 def assertSel(s):
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()]
29 sels.sort()
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)
41 self.assertEquals(0, len(sels[0].bindings))
42 self.assertEquals(0, len(sels[0].dependencies))
44 self.assertEquals(1, len(sels[1].bindings))
45 self.assertEquals('.', sels[1].bindings[0].insert)
47 self.assertEquals(1, len(sels[1].dependencies))
48 dep = sels[1].dependencies[0]
49 self.assertEquals('http://foo/Compiler.xml', dep.interface)
50 self.assertEquals(1, len(dep.bindings))
52 s1 = selections.Selections(p)
53 assertSel(s1)
55 xml = s1.toDOM().toxml("utf-8")
56 root = qdom.parse(StringIO(xml))
57 self.assertEquals(namespaces.XMLNS_IFACE, root.uri)
59 s2 = selections.Selections(root)
60 assertSel(s2)
62 suite = unittest.makeSuite(TestSelections)
63 if __name__ == '__main__':
64 sys.argv.append('-v')
65 unittest.main()