Catch cyclic dependency graphs and give a nice error instead of running out of stack
[zeroinstall/zeroinstall-mseaborn.git] / tests / testselections.py
blobf23664d949f43384c8c152b605f1e11659cec999
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)
40 self.assertEquals("bar", sels[1].attrs['http://namespace foo'])
42 self.assertEquals(0, len(sels[0].bindings))
43 self.assertEquals(0, len(sels[0].dependencies))
45 self.assertEquals(1, len(sels[1].bindings))
46 self.assertEquals('.', sels[1].bindings[0].insert)
48 self.assertEquals(1, len(sels[1].dependencies))
49 dep = sels[1].dependencies[0]
50 self.assertEquals('http://foo/Compiler.xml', dep.interface)
51 self.assertEquals(1, len(dep.bindings))
53 s1 = selections.Selections(p)
54 s1.selections['http://foo/Source.xml'].attrs['http://namespace foo'] = 'bar'
55 assertSel(s1)
57 xml = s1.toDOM().toxml("utf-8")
58 root = qdom.parse(StringIO(xml))
59 self.assertEquals(namespaces.XMLNS_IFACE, root.uri)
61 s2 = selections.Selections(root)
62 assertSel(s2)
64 suite = unittest.makeSuite(TestSelections)
65 if __name__ == '__main__':
66 sys.argv.append('-v')
67 unittest.main()