annotate emeraldtree/tests/test_tree.py @ 100:9d39d4bc2deb

ported to python 2.7 / >= 3.3 using six the port itself was half automated (using python-modernize) and half manual fixes and cleanups.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 May 2013 20:37:50 +0200
parents f7db63ba09f4
children 310ef85ca282
rev   line source
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
1 import py.test
53
d071598a93ef Tree support - Change module name
Bastian Blank <bblank@thinkmo.de>
parents: 49
diff changeset
2 from emeraldtree.tree import *
100
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
3 import six
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
4 from six import StringIO
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
5
54
6d2aaba7ac4d Tree - Move serialization code into classes
Bastian Blank <bblank@thinkmo.de>
parents: 53
diff changeset
6 def serialize(elem, namespaces={}):
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
7 file = StringIO()
67
47b1c1aa1a2b Tests for Tree - Use node write support
Bastian Blank <bblank@thinkmo.de>
parents: 63
diff changeset
8 elem.write(file.write, namespaces=namespaces)
3
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():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
12 elem = Element(u'a')
24
2015d11467bc Add testcase.
Bastian Blank <bblank@thinkmo.de>
parents: 23
diff changeset
13
4
705fc192cd9d Add new Node class and make it a base of Element.
Bastian Blank <bblank@thinkmo.de>
parents: 3
diff changeset
14 assert isinstance(elem, Node)
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
15 assert elem.tag == u'a'
18
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__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
18 elem = Element(u'a', children=(u'1', u'2', u'3', u'4', u'5'))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
19
49
78ef2b77ca4a Tests for ElementTree - Fix tests for default namespace, fix types
Bastian Blank <bblank@thinkmo.de>
parents: 40
diff changeset
20 assert len(elem) == 5
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
21
24
2015d11467bc Add testcase.
Bastian Blank <bblank@thinkmo.de>
parents: 23
diff changeset
22 def test_Element__nonzero__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
23 elem = Element(u'a')
24
2015d11467bc Add testcase.
Bastian Blank <bblank@thinkmo.de>
parents: 23
diff changeset
24
2015d11467bc Add testcase.
Bastian Blank <bblank@thinkmo.de>
parents: 23
diff changeset
25 assert elem
2015d11467bc Add testcase.
Bastian Blank <bblank@thinkmo.de>
parents: 23
diff changeset
26 assert len(elem) == 0
2015d11467bc Add testcase.
Bastian Blank <bblank@thinkmo.de>
parents: 23
diff changeset
27
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
28 def test_Element___getitem__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
29 elem = Element(u'a', children=(Element(u'b'), Element(u'c')))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
30
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
31 assert elem[0].tag == u'b'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
32 assert elem[1].tag == u'c'
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
33 assert len(elem[:1]) == 1
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
34 assert len(elem[:2]) == 2
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
35 assert len(elem[:3]) == 2
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
36 assert len(elem[1:3]) == 1
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
37 assert len(elem[2:3]) == 0
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
38 assert elem[:2][0].tag == u'b'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
39 assert elem[:2][1].tag == u'c'
18
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 def test_Element___setitem__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
42 elem = Element(u'a', children=(Element(u'b1'), Element(u'b2')))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
43
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
44 elem[0] = Element(u'c')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
45 assert elem[0].tag == u'c'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
46 assert elem[1].tag == u'b2'
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
47
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
48 elem[1] = Element(u'd')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
49 assert elem[0].tag == u'c'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
50 assert elem[1].tag == u'd'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
51
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
52 elem[0:0] = [Element(u'e')]
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
53 assert elem[0].tag == u'e'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
54 assert elem[1].tag == u'c'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
55 assert elem[2].tag == u'd'
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
56
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
57 def test_Element___delitem__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
58 elem = Element(u'a', children=(Element(u'b1'), Element(u'b2')))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
59
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
60 del elem[0]
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
61 assert len(elem) == 1
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
62 assert elem[0].tag == u'b2'
3
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
63
40db0b033d47 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
64 def test_Element_append():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
65 elem = Element(u'a')
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
66
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
67 elem.append(Element(u'b'))
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
68 assert len(elem) == 1
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
69 assert elem[0].tag == u'b'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
70
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
71 elem.append(Element(u'c'))
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
72 assert len(elem) == 2
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
73 assert elem[1].tag == u'c'
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
74
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
75 elem.append(u'd')
18
42e1c75e8bcb Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 16
diff changeset
76 assert len(elem) == 3
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
77 assert elem[2] == u'd'
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
78
30
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
79 def test_Element_extend():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
80 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
81
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
82 def test_Element_insert():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
83 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
84
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
85 def test_Element_remove():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
86 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
87
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
88 def test_Element_find():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
89 child_1 = Element(u'b1')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
90 child_2 = Element(u'b2')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
91 elem = Element(u'a', children=(child_1, child_2))
30
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
92
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
93 result = elem.find(u'b1')
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
94 assert result is child_1
30
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
95
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
96 result = elem.find(u'b2')
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
97 assert result is child_2
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
98
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
99 child_1 = Element(QName(u'b1', u'url1'))
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
100 child_2 = Element(QName(u'{url2}b2'))
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
101 elem = Element(u'a', children=(child_1, child_2))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
102
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
103 result = elem.find(u'{url1}b1')
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
104 assert result is child_1
30
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
105
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
106 def test_Element_findall():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
107 child_1 = Element(u'b1')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
108 child_2 = Element(u'b2')
49
78ef2b77ca4a Tests for ElementTree - Fix tests for default namespace, fix types
Bastian Blank <bblank@thinkmo.de>
parents: 40
diff changeset
109 child_3 = u"text"
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
110 elem = Element(u'a', children=(child_1, child_2, child_3))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
111
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
112 result = list(elem.findall(u'b1'))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
113 assert len(result) == 1
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
114 assert result[0] is child_1
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
115
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
116 result = list(elem.findall(u'b2'))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
117 assert len(result) == 1
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
118 assert result[0] is child_2
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
119
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
120 result = list(elem.findall(u'*'))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
121 assert len(result) == 3
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
122 assert result[0] is child_1
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
123 assert result[1] is child_2
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
124 assert result[2] is child_3
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
125
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
126 child_1 = Element(QName(u'b1', u'url1'))
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
127 child_2 = Element(QName(u'{url2}b2'))
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
128 elem = Element(u'a', children=(child_1, child_2))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
129
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
130 result = list(elem.findall(u'{url1}b1'))
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
131 assert len(result) == 1
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
132 assert result[0] is child_1
30
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
133
59
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
134 def test_Element_findall_tag_multimatch():
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
135 c1 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
136 c2 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
137 text = u"text"
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
138 b1 = Element(u'b', children=(c1, text, c2))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
139 b2 = Element(u'b')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
140 a1 = Element(u'a', children=(b1, b2, ))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
141
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
142 result = list(b1.findall(u'c'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
143 assert len(result) == 2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
144 assert result[0] is c1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
145 assert result[1] is c2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
146
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
147 result = list(a1.findall(u'c'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
148 assert len(result) == 0 # no 'c' childs
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
149
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
150 result = list(a1.findall(u'*/c'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
151 assert len(result) == 2 # but 2 'c' grandchilds
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
152 assert result[0] is c1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
153 assert result[1] is c2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
154
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
155 def test_Element_findall_bracketed_tag():
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
156 c1 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
157 c2 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
158 text = u"text"
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
159 b1 = Element(u'b', children=(c1, text, c2))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
160 b2 = Element(u'b')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
161 a1 = Element(u'a', children=(b1, b2, ))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
162
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
163 result = list(b1.findall(u'[c]'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
164 assert len(result) == 1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
165 assert result[0] is b1 # b1 has 'c' childs
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
166
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
167 result = list(a1.findall(u'*/[c]'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
168 assert len(result) == 1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
169 assert result[0] is b1 # b1 has 'c' childs
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
170
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
171 def test_Element_findall_dotdot():
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
172 py.test.skip('broken')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
173 c1 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
174 c2 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
175 text = u"text"
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
176 b1 = Element(u'b', children=(c1, text, c2))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
177 b2 = Element(u'b')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
178 a1 = Element(u'a', children=(b1, b2, ))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
179
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
180 result = list(c1.findall(u'../c'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
181 assert len(result) == 2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
182 assert result[0] is c1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
183 assert result[1] is c2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
184
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
185 def test_Element_findall_slashslash():
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
186 py.test.skip('broken')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
187 c1 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
188 c2 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
189 text = u"text"
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
190 b1 = Element(u'b', children=(c1, text, c2))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
191 b2 = Element(u'b')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
192 a1 = Element(u'a', children=(b1, b2, ))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
193
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
194 a1t = ElementTree(element=a1) # we need a tree to use //
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
195 result = list(a1t.findall(u'//c'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
196 assert len(result) == 2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
197 assert result[0] is c1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
198 assert result[1] is c2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
199
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
200 def test_Element_findall_dotslashslash():
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
201 py.test.skip('broken')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
202 c1 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
203 c2 = Element(u'c')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
204 text = u"text"
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
205 b1 = Element(u'b', children=(c1, text, c2))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
206 b2 = Element(u'b')
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
207 a1 = Element(u'a', children=(b1, b2, ))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
208
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
209 result = list(a1.findall(u'.//c'))
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
210 assert len(result) == 2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
211 assert result[0] is c1
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
212 assert result[1] is c2
33f5e57f1b97 more xpath tests, 3 of them are skipped because they fail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 58
diff changeset
213
60
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
214 def test_Element_findall_attribute():
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
215 c1 = Element(u'c')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
216 c2 = Element(u'c', testattr='testvalue')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
217 text = u"text"
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
218 b1 = Element(u'b', children=(c1, text, c2))
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
219 b2 = Element(u'b')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
220 a1 = Element(u'a', children=(b1, b2, ))
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
221
61
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
222 result = list(b1.findall(u"c[@testattr]"))
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
223 # note: does not work without c, like b1.findall(u"[@testattr]") - should it?
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
224 assert len(result) == 1
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
225 assert result[0] is c2
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
226
60
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
227 result = list(b1.findall(u"c[@testattr='testvalue']"))
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
228 # note: does not work without c, like b1.findall(u"[@testattr='testvalue']") - should it?
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
229 assert len(result) == 1
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
230 assert result[0] is c2
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
231
61
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
232 result = list(b1.findall(u"c[@testattr='othervalue']"))
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
233 # note: does not work without c, like b1.findall(u"[@testattr='othervalue']") - should it?
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
234 assert len(result) == 0
6c0a8bd9aa9a more xpath attribute tests (with other and without value)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 60
diff changeset
235
60
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
236 def test_Element_findall_position():
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
237 py.test.skip('not supported')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
238 c1 = Element(u'c')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
239 c2 = Element(u'c')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
240 text = u"text"
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
241 b1 = Element(u'b', children=(c1, text, c2))
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
242 b2 = Element(u'b')
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
243 a1 = Element(u'a', children=(b1, b2, ))
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
244
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
245 result = list(b1.findall(u'c[1]')) # note: index is 1-based, [1] (not [0]) is first
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
246 assert len(result) == 1
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
247 assert result[0] is c1
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
248
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
249 result = list(b1.findall(u'c[2]'))
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
250 assert len(result) == 1
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
251 assert result[0] is c2
0c6020f1a2be more xpath tests, 1 is skipped because it is unsupported
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 59
diff changeset
252
58
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
253 def test_Element_findtext_default():
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
254 elem = Element(u'a')
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
255 default_text = u'defaulttext'
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
256 result = elem.findtext(u'doesnotexist', default=default_text)
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
257 assert result is default_text
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
258
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
259 def test_Element_findtext():
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
260 child_text = u"text"
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
261 child = Element(u'b', children=(child_text, ))
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
262 elem = Element(u'a', children=(child, ))
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
263 result = elem.findtext(u'b')
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
264 assert result is child_text
9d0db78957e0 cosmetic changes for findtext() tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 57
diff changeset
265
30
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
266 def test_Element_clear():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
267 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
268
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
269 def test_Element_get():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
270 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
271
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
272 def test_Element_set():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
273 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
274
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
275 def test_Element_keys():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
276 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
277
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
278 def test_Element_items():
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
279 pass
96e02876b1a2 Testcases for ElementTree - Add testcases
Bastian Blank <bblank@thinkmo.de>
parents: 27
diff changeset
280
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
281 def test_Element_iter():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
282 elem = Element(u'a')
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
283 l = list(elem.iter())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
284 assert len(l) == 1
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
285
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
286 elem.append(u'b')
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
287 l = list(elem.iter())
38
6e38bcef6030 ElementTree - Make iterators return all childs
Bastian Blank <bblank@thinkmo.de>
parents: 32
diff changeset
288 assert len(l) == 2
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
289
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
290 elem.append(Element(u'c'))
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
291 l = list(elem.iter())
38
6e38bcef6030 ElementTree - Make iterators return all childs
Bastian Blank <bblank@thinkmo.de>
parents: 32
diff changeset
292 assert len(l) == 3
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
293
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
294 elem.append(u'd')
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
295 l = list(elem.iter())
38
6e38bcef6030 ElementTree - Make iterators return all childs
Bastian Blank <bblank@thinkmo.de>
parents: 32
diff changeset
296 assert len(l) == 4
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
297
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
298 def test_Element_itertext():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
299 elem = Element(u'a')
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
300 l = list(elem.itertext())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
301 assert len(l) == 0
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
302
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
303 elem.append(u'b')
8
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
304 l = list(elem.itertext())
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
305 assert len(l) == 1
e1d0cd336bf3 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 6
diff changeset
306
76
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
307 def test_Element_iter_elements():
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
308 elem = Element(u'a')
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
309 assert len(list(elem.iter_elements())) == 0
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
310
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
311 elem.append(Element(u'c'))
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
312 assert len(list(elem.iter_elements())) == 1
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
313
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
314 elem.append(u'b')
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
315 assert len(list(elem.iter_elements())) == 1
2175b8941596 Tree - Add element only iterator
Bastian Blank <bblank@thinkmo.de>
parents: 67
diff changeset
316
77
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
317 def test_Element_iter_elements_tree():
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
318 elem = Element(u'a')
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
319 assert len(list(elem.iter_elements_tree())) == 1
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
320
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
321 elem.append(u'b')
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
322 assert len(list(elem.iter_elements_tree())) == 1
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
323
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
324 elem.append(Element(u'c'))
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
325 assert len(list(elem.iter_elements_tree())) == 2
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
326
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
327 elem.append(u'd')
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
328 assert len(list(elem.iter_elements_tree())) == 2
f7db63ba09f4 Tree - Add element only tree iterator
Bastian Blank <bblank@thinkmo.de>
parents: 76
diff changeset
329
10
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
330 def test_Comment():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
331 elem = Comment(u'a')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
332 assert serialize(elem) == u'<!--a-->'
10
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
333 assert isinstance(elem, Node)
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
334
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
335 def test_ProcessingInstruction():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
336 elem = ProcessingInstruction(u'a')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
337 assert serialize(elem) == u'<?a?>'
10
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
338 assert isinstance(elem, ProcessingInstruction)
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
339
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
340 elem = ProcessingInstruction(u'a', u'b')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
341 assert serialize(elem) == u'<?a b?>'
10
fc4b72233da0 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 8
diff changeset
342
27
4dc29d2eac0e Force QName to be unicode.
Bastian Blank <bblank@thinkmo.de>
parents: 26
diff changeset
343 def test_QName___init__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
344 qname = QName(u'a')
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
345 assert qname.uri is None
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
346 assert qname.name == u'a'
100
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
347 assert isinstance(qname.name, six.text_type)
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
348 assert six.text_type(qname) == u'a'
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
349
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
350 qname = QName(u'{b}a')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
351 assert qname.uri == u'b'
100
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
352 assert isinstance(qname.uri, six.text_type)
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
353 assert qname.name == u'a'
100
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
354 assert six.text_type(qname) == u'{b}a'
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
355
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
356 qname = QName(u'a', u'b')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
357 assert qname.uri == u'b'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
358 assert qname.name == u'a'
100
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
359 assert six.text_type(qname) == u'{b}a'
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
360
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
361 py.test.raises(ValueError, QName, u'{bau')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
362 py.test.raises(ValueError, QName, u'{b}a', u'c')
15
60f59340b897 Remove argument ordering weirdness of QName.
Bastian Blank <bblank@thinkmo.de>
parents: 10
diff changeset
363
27
4dc29d2eac0e Force QName to be unicode.
Bastian Blank <bblank@thinkmo.de>
parents: 26
diff changeset
364 def test_QName___cmp__():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
365 qname1 = QName(u'a')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
366 qname2 = QName(u'a')
27
4dc29d2eac0e Force QName to be unicode.
Bastian Blank <bblank@thinkmo.de>
parents: 26
diff changeset
367
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
368 assert qname1 == qname2
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
369 assert qname1 == u'a'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
370 assert u'a' == qname1
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
371
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
372 qname1 = QName(u'a', u'b')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
373 qname2 = QName(u'{b}a')
32
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
374
7b5ed8600569 Testcases for ElementTree - Add testcases for find and findall
Bastian Blank <bblank@thinkmo.de>
parents: 30
diff changeset
375 assert qname1 == qname2
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
376 assert qname1 == u'{b}a'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
377 assert u'{b}a' == qname1
27
4dc29d2eac0e Force QName to be unicode.
Bastian Blank <bblank@thinkmo.de>
parents: 26
diff changeset
378
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
379 def test_XMLParser_simple1():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
380 elem = XML(u'<a />')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
381 assert elem.tag == u'a'
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
382 assert len(elem) == 0
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
383
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
384 def test_XMLParser_simple2():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
385 elem = XML(u'<a><b /></a>')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
386 assert elem.tag == u'a'
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
387 assert len(elem) == 1
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
388 assert elem[0].tag == u'b'
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
389 assert len(elem[0]) == 0
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
390
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
391 def test_XMLParser_text1():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
392 elem = XML(u'<a>b</a>')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
393 assert elem.tag == u'a'
23
4c1912ff58a3 Support initialization with children.
Bastian Blank <bblank@thinkmo.de>
parents: 18
diff changeset
394 assert isinstance(elem, Element)
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
395 assert len(elem) == 1
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
396 assert elem[0] == u'b'
100
9d39d4bc2deb ported to python 2.7 / >= 3.3 using six
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 77
diff changeset
397 assert isinstance(elem[0], six.text_type)
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
398
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
399 def test_XMLParser_text2():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
400 elem = XML(u'<a>b<c>d</c>d</a>')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
401 assert elem.tag == u'a'
6
ced434b6bf72 Add testcases.
Bastian Blank <bblank@thinkmo.de>
parents: 5
diff changeset
402 assert len(elem) == 3
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
403 assert elem[0] == u'b'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
404 assert elem[1].tag == u'c'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
405 assert elem[2] == u'd'
16
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
406
54
6d2aaba7ac4d Tree - Move serialization code into classes
Bastian Blank <bblank@thinkmo.de>
parents: 53
diff changeset
407 def test_XMLParser_namespace_1():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
408 elem = XML(u'<b xmlns="c" d="e"/>')
25
47ae505e63ea Parse tags and attribute names always in QName.
Bastian Blank <bblank@thinkmo.de>
parents: 24
diff changeset
409 assert isinstance(elem.tag, QName)
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
410 assert elem.tag == QName(u'b', u'c')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
411 assert elem.attrib == {QName(u'd', None): u'e'}
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
412 assert serialize(elem) == u'<ns0:b d="e" xmlns:ns0="c" />'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
413 assert serialize(elem, namespaces={u'c': u''}) == u'<b d="e" xmlns="c" />'
16
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
414
54
6d2aaba7ac4d Tree - Move serialization code into classes
Bastian Blank <bblank@thinkmo.de>
parents: 53
diff changeset
415 def test_XMLParser_namespace_2():
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
416 elem = XML(u'<a:b xmlns:a="c" d="e" a:f="g"/>')
40
a8382b8cded5 Testcases for ElementTree - Check all variants of namespace attributes
Bastian Blank <bblank@thinkmo.de>
parents: 38
diff changeset
417 assert isinstance(elem.tag, QName)
55
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
418 assert elem.tag == QName(u'b', u'c')
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
419 assert elem.attrib == {u'd': u'e', QName(u'f', u'c'): u'g'}
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
420 assert serialize(elem) == u'<ns0:b d="e" ns0:f="g" xmlns:ns0="c" />'
125ce968352d Tests for tree - Use unicode, style cleanup
Bastian Blank <bblank@thinkmo.de>
parents: 54
diff changeset
421 assert serialize(elem, namespaces={u'c': u''}) == u'<b d="e" f="g" xmlns="c" />'
16
533331338691 Use parsed values of QName in namespace lookup.
Bastian Blank <bblank@thinkmo.de>
parents: 15
diff changeset
422
40
a8382b8cded5 Testcases for ElementTree - Check all variants of namespace attributes
Bastian Blank <bblank@thinkmo.de>
parents: 38
diff changeset
423