Mercurial > genshi > mirror
annotate markup/tests/path.py @ 163:9c023c395e44 trunk
Support for XPath number literals including decimal places.
author | cmlenz |
---|---|
date | Wed, 16 Aug 2006 23:03:58 +0000 |
parents | 456039594db9 |
children | 1f6cb675a66c |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
66
59eb24184e9c
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
38
diff
changeset
|
3 # Copyright (C) 2006 Edgewall Software |
1 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
66
59eb24184e9c
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
38
diff
changeset
|
8 # are also available at http://markup.edgewall.org/wiki/License. |
1 | 9 # |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
66
59eb24184e9c
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
38
diff
changeset
|
12 # history and logs, available at http://markup.edgewall.org/log/. |
1 | 13 |
14 import doctest | |
15 import unittest | |
16 | |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
17 from markup.input import XML |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
18 from markup.path import Path, PathSyntaxError |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
19 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
20 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
21 class PathTestCase(unittest.TestCase): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
22 |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
23 def test_error_no_absolute_path(self): |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
24 self.assertRaises(PathSyntaxError, Path, '/root') |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
25 |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
26 def test_error_unsupported_axis(self): |
137 | 27 self.assertRaises(PathSyntaxError, Path, '..') |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
28 self.assertRaises(PathSyntaxError, Path, 'parent::ma') |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
29 |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
30 def test_1step(self): |
38
ee669cb9cccc
Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents:
27
diff
changeset
|
31 xml = XML('<root><elem/></root>') |
137 | 32 |
33 path = Path('elem') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
34 self.assertEqual('<Path "child::elem">', repr(path)) |
137 | 35 self.assertEqual('<elem/>', path.select(xml).render()) |
36 | |
37 path = Path('child::elem') | |
38 self.assertEqual('<Path "child::elem">', repr(path)) | |
39 self.assertEqual('<elem/>', path.select(xml).render()) | |
40 | |
41 path = Path('//elem') | |
42 self.assertEqual('<Path "descendant-or-self::node()/child::elem">', | |
43 repr(path)) | |
44 self.assertEqual('<elem/>', path.select(xml).render()) | |
45 | |
46 path = Path('descendant::elem') | |
47 self.assertEqual('<Path "descendant::elem">', repr(path)) | |
48 self.assertEqual('<elem/>', path.select(xml).render()) | |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
49 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
50 def test_1step_self(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
51 xml = XML('<root><elem/></root>') |
137 | 52 |
53 path = Path('.') | |
54 self.assertEqual('<Path "self::node()">', repr(path)) | |
55 self.assertEqual('<root><elem/></root>', path.select(xml).render()) | |
56 | |
57 path = Path('self::node()') | |
58 self.assertEqual('<Path "self::node()">', repr(path)) | |
59 self.assertEqual('<root><elem/></root>', path.select(xml).render()) | |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
60 |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
61 def test_1step_wildcard(self): |
38
ee669cb9cccc
Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents:
27
diff
changeset
|
62 xml = XML('<root><elem/></root>') |
137 | 63 |
64 path = Path('*') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
65 self.assertEqual('<Path "child::*">', repr(path)) |
137 | 66 self.assertEqual('<elem/>', path.select(xml).render()) |
67 | |
68 path = Path('child::*') | |
69 self.assertEqual('<Path "child::*">', repr(path)) | |
70 self.assertEqual('<elem/>', path.select(xml).render()) | |
71 | |
72 path = Path('child::node()') | |
73 self.assertEqual('<Path "child::node()">', repr(path)) | |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
74 self.assertEqual('<elem/>', Path('child::node()').select(xml).render()) |
137 | 75 |
76 path = Path('//*') | |
77 self.assertEqual('<Path "descendant-or-self::node()/child::*">', | |
78 repr(path)) | |
79 self.assertEqual('<elem/>', path.select(xml).render()) | |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
80 |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
81 def test_1step_attribute(self): |
138 | 82 path = Path('@foo') |
83 self.assertEqual('<Path "attribute::foo">', repr(path)) | |
84 self.assertEqual('', path.select(XML('<root/>')).render()) | |
85 | |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
86 xml = XML('<root foo="bar"/>') |
138 | 87 self.assertEqual('bar', path.select(xml).render()) |
88 | |
89 path = Path('./@foo') | |
90 self.assertEqual('<Path "self::node()/attribute::foo">', repr(path)) | |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
91 self.assertEqual('bar', Path('./@foo').select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
92 |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
93 def test_1step_text(self): |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
94 xml = XML('<root>Hey</root>') |
138 | 95 |
96 path = Path('text()') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
97 self.assertEqual('<Path "child::text()">', repr(path)) |
138 | 98 self.assertEqual('Hey', path.select(xml).render()) |
99 | |
100 path = Path('./text()') | |
101 self.assertEqual('<Path "self::node()/child::text()">', repr(path)) | |
102 self.assertEqual('Hey', path.select(xml).render()) | |
103 | |
104 path = Path('//text()') | |
105 self.assertEqual('<Path "descendant-or-self::node()/child::text()">', | |
106 repr(path)) | |
107 self.assertEqual('Hey', path.select(xml).render()) | |
108 | |
109 path = Path('.//text()') | |
110 self.assertEqual('<Path "self::node()/child::text()">', repr(path)) | |
111 self.assertEqual('Hey', path.select(xml).render()) | |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
112 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
113 def test_2step(self): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
114 xml = XML('<root><foo/><bar/></root>') |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
115 self.assertEqual('<foo/><bar/>', Path('*').select(xml).render()) |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
116 self.assertEqual('<bar/>', Path('bar').select(xml).render()) |
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
117 self.assertEqual('', Path('baz').select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
118 |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
119 def test_2step_attribute(self): |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
120 xml = XML('<elem class="x"><span id="joe">Hey Joe</span></elem>') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
121 #self.assertEqual('x', Path('@*').select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
122 #self.assertEqual('x', Path('./@*').select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
123 #self.assertEqual('xjoe', Path('//@*').select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
124 self.assertEqual('joe', Path('*/@*').select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
125 |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
126 xml = XML('<elem><foo id="1"/>foo id="2"/></elem>') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
127 #self.assertEqual('', Path('@*').select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
128 #self.assertEqual('12', Path('foo/@*').select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
129 |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
130 def test_2step_complex(self): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
131 xml = XML('<root><foo><bar/></foo></root>') |
138 | 132 |
133 path = Path('foo/bar') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
134 self.assertEqual('<Path "child::foo/child::bar">', repr(path)) |
138 | 135 self.assertEqual('<bar/>', path.select(xml).render()) |
136 | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
137 path = Path('./bar') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
138 self.assertEqual('<Path "self::node()/child::bar">', repr(path)) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
139 #self.assertEqual('', path.select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
140 |
138 | 141 path = Path('foo/*') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
142 self.assertEqual('<Path "child::foo/child::*">', repr(path)) |
138 | 143 self.assertEqual('<bar/>', path.select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
144 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
145 xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
146 path = Path('./bar') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
147 self.assertEqual('<Path "self::node()/child::bar">', repr(path)) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
148 #self.assertEqual('<bar id="2"/>', path.select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
149 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
150 def test_2step_text(self): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
151 xml = XML('<root><item>Foo</item></root>') |
138 | 152 |
153 path = Path('item/text()') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
154 self.assertEqual('<Path "child::item/child::text()">', repr(path)) |
138 | 155 self.assertEqual('Foo', path.select(xml).render()) |
156 | |
157 path = Path('*/text()') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
158 self.assertEqual('<Path "child::*/child::text()">', repr(path)) |
138 | 159 self.assertEqual('Foo', path.select(xml).render()) |
160 | |
161 path = Path('//text()') | |
162 self.assertEqual('<Path "descendant-or-self::node()/child::text()">', | |
163 repr(path)) | |
164 self.assertEqual('Foo', path.select(xml).render()) | |
165 | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
166 path = Path('./text()') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
167 self.assertEqual('<Path "self::node()/child::text()">', repr(path)) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
168 #self.assertEqual('', path.select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
169 |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
170 xml = XML('<root><item>Foo</item><item>Bar</item></root>') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
171 path = Path('item/text()') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
172 self.assertEqual('<Path "child::item/child::text()">', repr(path)) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
173 self.assertEqual('FooBar', path.select(xml).render()) |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
174 |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
175 xml = XML('<root><item>Foo</item><item>Bar</item></root>') |
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
176 self.assertEqual('FooBar', path.select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
177 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
178 def test_3step(self): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
179 xml = XML('<root><foo><bar/></foo></root>') |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
180 path = Path('foo/*') |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
181 self.assertEqual('<Path "child::foo/child::*">', |
138 | 182 repr(path)) |
183 self.assertEqual('<bar/>', path.select(xml).render()) | |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
184 |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
185 def test_3step_complex(self): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
186 xml = XML('<root><foo><bar/></foo></root>') |
138 | 187 path = Path('*/bar') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
188 self.assertEqual('<Path "child::*/child::bar">', repr(path)) |
138 | 189 self.assertEqual('<bar/>', path.select(xml).render()) |
190 | |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
191 xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>') |
138 | 192 path = Path('//bar') |
193 self.assertEqual('<Path "descendant-or-self::node()/child::bar">', | |
194 repr(path)) | |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
195 self.assertEqual('<bar id="1"/><bar id="2"/>', |
138 | 196 path.select(xml).render()) |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
197 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
198 def test_node_type_comment(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
199 xml = XML('<root><!-- commented --></root>') |
138 | 200 path = Path('comment()') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
201 self.assertEqual('<Path "child::comment()">', repr(path)) |
138 | 202 self.assertEqual('<!-- commented -->', path.select(xml).render()) |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
203 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
204 def test_node_type_text(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
205 xml = XML('<root>Some text <br/>in here.</root>') |
138 | 206 path = Path('text()') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
207 self.assertEqual('<Path "child::text()">', repr(path)) |
138 | 208 self.assertEqual('Some text in here.', path.select(xml).render()) |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
209 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
210 def test_node_type_node(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
211 xml = XML('<root>Some text <br/>in here.</root>') |
138 | 212 path = Path('node()') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
213 self.assertEqual('<Path "child::node()">', repr(path)) |
138 | 214 self.assertEqual('Some text <br/>in here.', path.select(xml).render()) |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
215 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
216 def test_node_type_processing_instruction(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
217 xml = XML('<?python x = 2 * 3 ?><root><?php echo("x") ?></root>') |
138 | 218 |
219 path = Path('processing-instruction()') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
220 self.assertEqual('<Path "child::processing-instruction()">', |
138 | 221 repr(path)) |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
222 self.assertEqual('<?python x = 2 * 3 ?><?php echo("x") ?>', |
138 | 223 path.select(xml).render()) |
224 | |
225 path = Path('processing-instruction("php")') | |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
226 self.assertEqual('<Path "child::processing-instruction(\"php\")">', |
138 | 227 repr(path)) |
228 self.assertEqual('<?php echo("x") ?>', path.select(xml).render()) | |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
229 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
230 def test_simple_union(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
231 xml = XML('<root>Oh <foo>my</foo></root>') |
138 | 232 path = Path('*|text()') |
145
47bbd9d2a5af
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
138
diff
changeset
|
233 self.assertEqual('<Path "child::*|child::text()">', |
138 | 234 repr(path)) |
235 self.assertEqual('Oh <foo>my</foo>', path.select(xml).render()) | |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
236 |
121
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
237 def test_predicate_name(self): |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
238 xml = XML('<root><foo/><bar/></root>') |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
239 self.assertEqual('<foo/>', |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
240 Path('*[name()="foo"]').select(xml).render()) |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
241 |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
242 def test_predicate_localname(self): |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
243 xml = XML('<root><foo xmlns="NS"/><bar/></root>') |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
244 self.assertEqual('<foo xmlns="NS"/>', |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
245 Path('*[local-name()="foo"]').select(xml).render()) |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
246 |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
247 def test_predicate_namespace(self): |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
248 xml = XML('<root><foo xmlns="NS"/><bar/></root>') |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
249 self.assertEqual('<foo xmlns="NS"/>', |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
250 Path('*[namespace-uri()="NS"]').select(xml).render()) |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
251 |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
252 def test_predicate_not_name(self): |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
253 xml = XML('<root><foo/><bar/></root>') |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
254 self.assertEqual('<bar/>', |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
255 Path('*[not(name()="foo")]').select(xml).render()) |
062e51ad7b19
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
256 |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
257 def test_predicate_attr(self): |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
258 xml = XML('<root><item/><item important="very"/></root>') |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
259 self.assertEqual('<item important="very"/>', |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
260 Path('item[@important]').select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
261 self.assertEqual('<item important="very"/>', |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
262 Path('item[@important="very"]').select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
263 |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
264 def test_predicate_attr_equality(self): |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
265 xml = XML('<root><item/><item important="notso"/></root>') |
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
266 self.assertEqual('', |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
267 Path('item[@important="very"]').select(xml).render()) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
268 self.assertEqual('<item/><item important="notso"/>', |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
269 Path('item[@important!="very"]').select(xml).render()) |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
270 |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
271 def test_predicate_attr_greater_than(self): |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
272 xml = XML('<root><item priority="3"/></root>') |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
273 self.assertEqual('', |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
274 Path('item[@priority>3]').select(xml).render()) |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
275 self.assertEqual('<item priority="3"/>', |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
276 Path('item[@priority>2]').select(xml).render()) |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
277 |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
278 def test_predicate_attr_less_than(self): |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
279 xml = XML('<root><item priority="3"/></root>') |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
280 self.assertEqual('', |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
281 Path('item[@priority<3]').select(xml).render()) |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
282 self.assertEqual('<item priority="3"/>', |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
283 Path('item[@priority<4]').select(xml).render()) |
1 | 284 |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
285 def test_predicate_attr_and(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
286 xml = XML('<root><item/><item important="very"/></root>') |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
287 path = Path('item[@important and @important="very"]') |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
288 self.assertEqual('<item important="very"/>', path.select(xml).render()) |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
289 path = Path('item[@important and @important="notso"]') |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
290 self.assertEqual('', path.select(xml).render()) |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
291 |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
292 def test_predicate_attr_or(self): |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
293 xml = XML('<root><item/><item important="very"/></root>') |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
294 path = Path('item[@urgent or @important]') |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
295 self.assertEqual('<item important="very"/>', path.select(xml).render()) |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
296 path = Path('item[@urgent or @notso]') |
106
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
297 self.assertEqual('', path.select(xml).render()) |
f9473bdc93b2
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
298 |
155
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
299 def test_predicate_boolean_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
300 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
301 path = Path('*[boolean("")]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
302 self.assertEqual('', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
303 path = Path('*[boolean("yo")]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
304 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
305 path = Path('*[boolean(0)]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
306 self.assertEqual('', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
307 path = Path('*[boolean(42)]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
308 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
309 path = Path('*[boolean(false())]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
310 self.assertEqual('', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
311 path = Path('*[boolean(true())]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
312 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
313 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
314 def test_predicate_ceil_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
315 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
316 path = Path('*[ceiling("4.5")=5]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
317 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
318 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
319 def test_predicate_concat_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
320 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
321 path = Path('*[name()=concat("f", "oo")]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
322 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
323 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
324 def test_predicate_contains_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
325 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
326 path = Path('*[contains(name(), "oo")]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
327 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
328 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
329 def test_predicate_false_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
330 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
331 path = Path('*[false()]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
332 self.assertEqual('', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
333 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
334 def test_predicate_floor_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
335 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
336 path = Path('*[floor("4.5")=4]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
337 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
338 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
339 def test_predicate_normalize_space_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
340 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
341 path = Path('*[normalize-space(" foo bar ")="foo bar"]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
342 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
343 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
344 def test_predicate_number_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
345 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
346 path = Path('*[number("3.0")=3]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
347 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
163
9c023c395e44
Support for XPath number literals including decimal places.
cmlenz
parents:
162
diff
changeset
|
348 path = Path('*[number("3.0")=3.0]') |
9c023c395e44
Support for XPath number literals including decimal places.
cmlenz
parents:
162
diff
changeset
|
349 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9c023c395e44
Support for XPath number literals including decimal places.
cmlenz
parents:
162
diff
changeset
|
350 path = Path('*[number("0.1")=.1]') |
9c023c395e44
Support for XPath number literals including decimal places.
cmlenz
parents:
162
diff
changeset
|
351 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
155
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
352 |
162
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
353 def test_predicate_round_function(self): |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
354 xml = XML('<root><foo>bar</foo></root>') |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
355 path = Path('*[round("4.4")=4]') |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
356 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
357 path = Path('*[round("4.6")=5]') |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
358 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
456039594db9
Implement the XPath relational operators and the `round()` function.
cmlenz
parents:
155
diff
changeset
|
359 |
155
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
360 def test_predicate_starts_with_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
361 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
362 path = Path('*[starts-with(name(), "f")]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
363 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
364 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
365 def test_predicate_string_length_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
366 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
367 path = Path('*[string-length(name())=3]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
368 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
369 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
370 def test_predicate_substring_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
371 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
372 path = Path('*[substring(name(), 1)="oo"]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
373 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
374 path = Path('*[substring(name(), 1, 1)="o"]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
375 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
376 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
377 def test_predicate_substring_after_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
378 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
379 path = Path('*[substring-after(name(), "f")="oo"]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
380 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
381 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
382 def test_predicate_substring_before_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
383 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
384 path = Path('*[substring-before(name(), "oo")="f"]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
385 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
386 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
387 def test_predicate_translate_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
388 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
389 path = Path('*[translate(name(), "fo", "ba")="baa"]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
390 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
391 |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
392 def test_predicate_true_function(self): |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
393 xml = XML('<root><foo>bar</foo></root>') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
394 path = Path('*[true()]') |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
395 self.assertEqual('<foo>bar</foo>', path.select(xml).render()) |
9a5aedda1099
* String literals in XPath expressions that contains spaces are now tokenizes correctly.
cmlenz
parents:
145
diff
changeset
|
396 |
1 | 397 |
398 def suite(): | |
399 suite = unittest.TestSuite() | |
111
2368c3becc52
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
400 suite.addTest(doctest.DocTestSuite(Path.__module__)) |
26
3c1a022be04c
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
401 suite.addTest(unittest.makeSuite(PathTestCase, 'test')) |
1 | 402 return suite |
403 | |
404 if __name__ == '__main__': | |
405 unittest.main(defaultTest='suite') |