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