"Compile" is now a sub-menu with Automatic and Manual options
[zeroinstall/solver.git] / tests / testqdom.py
blob544e258d53f0ab0d97e8907477fdc894b3ac707c
1 #!/usr/bin/env python2.5
2 from basetest import BaseTest
3 import sys
4 from StringIO import StringIO
5 import unittest
7 sys.path.insert(0, '..')
9 from zeroinstall.injector import qdom
11 def parseString(s):
12 return qdom.parse(StringIO(s))
14 class TestQDom(BaseTest):
15 def testSimple(self):
16 root = parseString('<?xml version="1.0"?><root/>')
17 assert root.name == 'root'
18 assert root.uri == None
19 assert root.content == ''
21 def testText(self):
22 root = parseString('<?xml version="1.0"?><root> Hi </root>')
23 assert root.name == 'root'
24 assert root.uri == None
25 assert root.content == 'Hi'
26 assert root.childNodes == []
28 def testNS(self):
29 root = parseString('<?xml version="1.0"?>' +
30 '<x:root xmlns:x="http://myns.com/foo"/>')
31 assert root.name == 'root'
32 assert root.uri == 'http://myns.com/foo'
33 assert root.content == ''
34 assert root.childNodes == []
36 def testAttrs(self):
37 root = parseString('<?xml version="1.0"?>' +
38 '<root x:foo="bar" bar="baz" xmlns:x="http://myns.com/foo"/>')
39 assert root.name == 'root'
40 assert root.uri == None
41 assert root.content == ''
42 assert root.childNodes == []
44 assert root.attrs.get('http://myns.com/foo foo') == 'bar'
45 assert root.attrs.get('bar') == 'baz'
47 def testNested(self):
48 root = parseString('<?xml version="1.0"?><root>' +
49 '<name>Bob</name><age>3</age></root>')
50 assert root.name == 'root'
51 assert root.uri == None
52 assert root.content == ''
53 assert len(root.childNodes) == 2
55 assert root.childNodes[0].name == 'name'
56 assert root.childNodes[0].uri == None
57 assert root.childNodes[0].content == 'Bob'
58 assert root.childNodes[0].childNodes == []
60 assert root.childNodes[1].name == 'age'
61 assert root.childNodes[1].uri == None
62 assert root.childNodes[1].content == '3'
63 assert root.childNodes[1].childNodes == []
65 def testStr(self):
66 root = parseString('<?xml version="1.0"?><root>' +
67 '<sub x="2">hi</sub><empty/></root>')
68 assert 'root' in str(root)
70 suite = unittest.makeSuite(TestQDom)
71 if __name__ == '__main__':
72 sys.argv.append('-v')
73 unittest.main()