2 from basetest
import BaseTest
7 sys
.path
.insert(0, '..')
9 from zeroinstall
.injector
import qdom
12 return qdom
.parse(BytesIO(s
.encode('utf-8')))
14 class TestQDom(BaseTest
):
16 root
= parseString('<?xml version="1.0"?><root/>')
17 assert root
.name
== 'root'
18 assert root
.uri
== None
19 assert root
.content
== ''
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
== []
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
== []
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'
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
== []
66 root
= parseString('<?xml version="1.0"?><root>' +
67 '<sub x="2">hi</sub><empty/></root>')
68 assert 'root' in str(root
)
70 if __name__
== '__main__':