annotate emeraldtree/tests/test_tree.py @ 67:47b1c1aa1a2b

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