annotate emeraldtree/tests/test_ElementTree.py @ 18:42e1c75e8bcb

Add testcases. emeraldtree/tests/test_ElementTree.py: Add testcases for Element functions.
author Bastian Blank <bblank@thinkmo.de>
date Sat, 31 May 2008 19:05:29 +0200
parents 533331338691
children 4c1912ff58a3
rev   line source
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
1 import py.test
4
705fc192cd9d Add new Node class and make it a base of Element.
Bastian Blank <bblank@thinkmo.de>
parents: 3
diff changeset
2 from emeraldtree.ElementTree import *
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
4 def serialize(elem, **options):
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
5 from cStringIO import StringIO
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
6 file = StringIO()
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
7 tree = ElementTree(elem)
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
8 tree.write(file, **options)
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
9 return file.getvalue()
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
10
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
11 def test_Element():
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
12 elem = Element('a')
4
705fc192cd9d Add new Node class and make it a base of Element.
Bastian Blank <bblank@thinkmo.de>
parents: 3
diff changeset
13 assert isinstance(elem, Node)
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
14 assert elem.tag == 'a'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
15 assert elem
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
16
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
17 def test_Element__len__():
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
18 elem = Element('a')
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
19 elem._children = range(10)
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
20
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
21 assert len(elem) == 10
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
22
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
23 def test_Element___getitem__():
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
24 elem = Element('a')
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
25 elem._children = [Element('b'), Element('c')]
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
26
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
27 assert elem[0].tag == 'b'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
28 assert elem[1].tag == 'c'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
29 assert len(elem[:1]) == 1
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
30 assert len(elem[:2]) == 2
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
31 assert len(elem[:3]) == 2
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
32 assert len(elem[1:3]) == 1
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
33 assert len(elem[2:3]) == 0
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
34 assert elem[:2][0].tag == 'b'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
35 assert elem[:2][1].tag == 'c'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
36
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
37 def test_Element___setitem__():
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
38 elem = Element('a')
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
39 elem._children = [Element('b1'), Element('b2')]
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
40
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
41 elem[0] = Element('c')
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
42 assert elem[0].tag == 'c'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
43 assert elem[1].tag == 'b2'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
44
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
45 elem[1] = Element('d')
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
46 assert elem[0].tag == 'c'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
47 assert elem[1].tag == 'd'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
48
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
49 elem[0:0] = [Element('e')]
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
50 assert elem[0].tag == 'e'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
51 assert elem[1].tag == 'c'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
52 assert elem[2].tag == 'd'
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
53
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
54 def test_Element___delitem__():
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
55 elem = Element('a')
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
56 elem._children = [Element('b1'), Element('b2')]
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
57
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
58 del elem[0]
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
59 assert len(elem) == 1
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
60 assert elem[0].tag == 'b2'
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
61
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
62 def test_Element_append():
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
63 elem = Element('a')
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
64 elem.append(Element('b'))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
65 assert len(elem) == 1
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
66 assert elem[0].tag == 'b'
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
67
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
68 elem.append(Element('c'))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
69 assert len(elem) == 2
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
70 assert elem[1].tag == 'c'
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
71
5
9b72cb3ef3c9 Support strings a children.
Bastian Blank <bblank@thinkmo.de>
parents: 4
diff changeset
72 elem.append('d')
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
73 assert len(elem) == 3
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
74 assert elem[2] == 'd'
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
75
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
76 def test_Element_iter():
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
77 elem = Element('a')
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
78 l = list(elem.iter())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
79 assert len(l) == 1
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
80
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
81 elem.append('b')
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
82 l = list(elem.iter())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
83 assert len(l) == 1
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
84
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
85 elem.append(Element('c'))
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
86 l = list(elem.iter())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
87 assert len(l) == 2
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
88
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
89 elem.append('d')
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
90 l = list(elem.iter())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
91 assert len(l) == 2
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
92
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
93 def test_Element_itertext():
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
94 elem = Element('a')
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
95 l = list(elem.itertext())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
96 assert len(l) == 0
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
97
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
98 elem.append('b')
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
99 l = list(elem.itertext())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
100 assert len(l) == 1
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
101
10
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
102 def test_Comment():
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
103 elem = Comment('a')
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
104 assert serialize(elem) == '<!--a-->'
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
105 assert isinstance(elem, Node)
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
106
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
107 def test_ProcessingInstruction():
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
108 elem = ProcessingInstruction('a')
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
109 assert serialize(elem) == '<?a?>'
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
110 assert isinstance(elem, ProcessingInstruction)
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
111
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
112 elem = ProcessingInstruction('a', 'b')
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
113 assert serialize(elem) == '<?a b?>'
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
114
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
115 def test_QName():
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
116 qname = QName('a')
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
117 assert qname.uri is None
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
118 assert qname.name == 'a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
119 assert str(qname) == 'a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
120 assert qname.text == 'a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
121
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
122 qname = QName('{b}a')
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
123 assert qname.uri == 'b'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
124 assert qname.name == 'a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
125 assert str(qname) == '{b}a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
126 assert qname.text == '{b}a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
127
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
128 qname = QName('a', 'b')
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
129 assert qname.uri == 'b'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
130 assert qname.name == 'a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
131 assert str(qname) == '{b}a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
132 assert qname.text == '{b}a'
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
133
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
134 py.test.raises(ValueError, QName, '{ba')
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
135 py.test.raises(ValueError, QName, '{b}a', 'c')
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
136
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
137 def test_XMLParser_simple1():
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
138 elem = XML('<a />')
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
139 assert elem.tag == 'a'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
140 assert len(elem) == 0
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
141
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
142 def test_XMLParser_simple2():
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
143 elem = XML('<a><b /></a>')
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
144 assert elem.tag == 'a'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
145 assert len(elem) == 1
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
146 assert elem[0].tag == 'b'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
147 assert len(elem[0]) == 0
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
148
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
149 def test_XMLParser_text1():
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
150 elem = XML('<a>b</a>')
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
151 assert elem.tag == 'a'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
152 assert len(elem) == 1
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
153
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
154 def test_XMLParser_text2():
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
155 elem = XML('<a>b<c>d</c>d</a>')
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
156 assert elem.tag == 'a'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
157 assert len(elem) == 3
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
158 assert elem[0] == 'b'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
159 assert elem[1].tag == 'c'
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
160 assert elem[2] == 'd'
16
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
161
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
162 def test_XMLParser_namespace():
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
163 elem = XML('<a:a xmlns:a="a"/>')
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
164 assert elem.tag == QName('a', 'a')
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
165 assert serialize(elem) == '<ns0:a xmlns:ns0="a" />'
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
166
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
167 elem = XML('<a:a xmlns:a="a" a="a"/>')
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
168 assert elem.tag == QName('a', 'a')
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
169 assert elem.attrib == {'a': 'a'}
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
170 assert serialize(elem) == '<ns0:a a="a" xmlns:ns0="a" />'
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
171
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
172 elem = XML('<a:a xmlns:a="a" a:a="a"/>')
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
173 assert elem.tag == QName('a', 'a')
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
174 assert elem.attrib == {QName('a', 'a'): 'a'}
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
175 assert serialize(elem) == '<ns0:a ns0:a="a" xmlns:ns0="a" />'
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
176