Mercurial > genshi > genshi-test
annotate markup/tests/path.py @ 138:d91e1e822969
Add some more assertions to the XPath tests.
author | cmlenz |
---|---|
date | Wed, 09 Aug 2006 12:07:26 +0000 |
parents | 38ddb21b6fa4 |
children | 56d534eb53f9 |
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 |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
30 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
|
31 xml = XML('<root><elem/></root>') |
137 | 32 |
33 path = Path('elem') | |
34 self.assertEqual('<Path "descendant::elem">', repr(path)) | |
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
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
49 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
50 def test_1step_self(self): |
61fa4cadb766
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
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
60 |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
61 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
|
62 xml = XML('<root><elem/></root>') |
137 | 63 |
64 path = Path('*') | |
65 self.assertEqual('<Path "descendant::*">', repr(path)) | |
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
8a4d9064f363
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
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
80 |
26
039fc5b87405
* 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
8a4d9064f363
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
8a4d9064f363
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
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
92 |
111
8a4d9064f363
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
93 def test_1step_text(self): |
8a4d9064f363
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()') | |
97 self.assertEqual('<Path "descendant::text()">', repr(path)) | |
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
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
112 |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
113 def test_2step(self): |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
114 xml = XML('<root><foo/><bar/></root>') |
111
8a4d9064f363
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
115 self.assertEqual('<foo/><bar/>', Path('*').select(xml).render()) |
8a4d9064f363
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
116 self.assertEqual('<bar/>', Path('bar').select(xml).render()) |
8a4d9064f363
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
117 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
|
118 |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
119 def test_2step_complex(self): |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
120 xml = XML('<root><foo><bar/></foo></root>') |
138 | 121 |
122 path = Path('foo/bar') | |
123 self.assertEqual('<Path "descendant::foo/child::bar">', repr(path)) | |
124 self.assertEqual('<bar/>', path.select(xml).render()) | |
125 | |
126 path = Path('foo/*') | |
127 self.assertEqual('<Path "descendant::foo/child::*">', repr(path)) | |
128 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
|
129 |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
130 xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>') |
137 | 131 self.assertEqual('<bar id="1"/><bar id="2"/>', |
132 Path('bar').select(xml).render()) | |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
133 |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
134 def test_2step_text(self): |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
135 xml = XML('<root><item>Foo</item></root>') |
138 | 136 |
137 path = Path('item/text()') | |
138 self.assertEqual('<Path "descendant::item/child::text()">', repr(path)) | |
139 self.assertEqual('Foo', path.select(xml).render()) | |
140 | |
141 path = Path('*/text()') | |
142 self.assertEqual('<Path "descendant::*/child::text()">', repr(path)) | |
143 self.assertEqual('Foo', path.select(xml).render()) | |
144 | |
145 path = Path('//text()') | |
146 self.assertEqual('<Path "descendant-or-self::node()/child::text()">', | |
147 repr(path)) | |
148 self.assertEqual('Foo', path.select(xml).render()) | |
149 | |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
150 xml = XML('<root><item>Foo</item><item>Bar</item></root>') |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
151 self.assertEqual('FooBar', Path('item/text()').select(xml).render()) |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
152 |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
153 def test_3step(self): |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
154 xml = XML('<root><foo><bar/></foo></root>') |
138 | 155 path = Path('root/foo/*') |
156 self.assertEqual('<Path "descendant::root/child::foo/child::*">', | |
157 repr(path)) | |
158 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
|
159 |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
160 def test_3step_complex(self): |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
161 xml = XML('<root><foo><bar/></foo></root>') |
138 | 162 path = Path('*/bar') |
163 self.assertEqual('<Path "descendant::*/child::bar">', repr(path)) | |
164 self.assertEqual('<bar/>', path.select(xml).render()) | |
165 | |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
166 xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>') |
138 | 167 path = Path('//bar') |
168 self.assertEqual('<Path "descendant-or-self::node()/child::bar">', | |
169 repr(path)) | |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
170 self.assertEqual('<bar id="1"/><bar id="2"/>', |
138 | 171 path.select(xml).render()) |
106
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
172 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
173 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
|
174 xml = XML('<root><!-- commented --></root>') |
138 | 175 path = Path('comment()') |
176 self.assertEqual('<Path "descendant::comment()">', repr(path)) | |
177 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
|
178 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
179 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
|
180 xml = XML('<root>Some text <br/>in here.</root>') |
138 | 181 path = Path('text()') |
182 self.assertEqual('<Path "descendant::text()">', repr(path)) | |
183 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
|
184 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
185 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
|
186 xml = XML('<root>Some text <br/>in here.</root>') |
138 | 187 path = Path('node()') |
188 self.assertEqual('<Path "descendant::node()">', repr(path)) | |
189 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
|
190 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
191 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
|
192 xml = XML('<?python x = 2 * 3 ?><root><?php echo("x") ?></root>') |
138 | 193 |
194 path = Path('processing-instruction()') | |
195 self.assertEqual('<Path "descendant::processing-instruction()">', | |
196 repr(path)) | |
106
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
197 self.assertEqual('<?python x = 2 * 3 ?><?php echo("x") ?>', |
138 | 198 path.select(xml).render()) |
199 | |
200 path = Path('processing-instruction("php")') | |
201 self.assertEqual('<Path "descendant::processing-instruction(\"php\")">', | |
202 repr(path)) | |
203 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
|
204 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
205 def test_simple_union(self): |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
206 xml = XML('<root>Oh <foo>my</foo></root>') |
138 | 207 path = Path('*|text()') |
208 self.assertEqual('<Path "descendant::*|descendant::text()">', | |
209 repr(path)) | |
210 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
|
211 |
121
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
212 def test_predicate_name(self): |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
213 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
|
214 self.assertEqual('<foo/>', |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
215 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
|
216 |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
217 def test_predicate_localname(self): |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
218 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
|
219 self.assertEqual('<foo xmlns="NS"/>', |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
220 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
|
221 |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
222 def test_predicate_namespace(self): |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
223 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
|
224 self.assertEqual('<foo xmlns="NS"/>', |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
225 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
|
226 |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
227 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
|
228 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
|
229 self.assertEqual('<bar/>', |
22a7080ed242
Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents:
111
diff
changeset
|
230 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
|
231 |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
232 def test_predicate_attr(self): |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
233 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
|
234 self.assertEqual('<item important="very"/>', |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
235 Path('root/item[@important]').select(xml).render()) |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
236 self.assertEqual('<item important="very"/>', |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
237 Path('root/item[@important="very"]').select(xml).render()) |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
238 |
106
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
239 def test_predicate_attr_equality(self): |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
240 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
|
241 self.assertEqual('', |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
242 Path('root/item[@important="very"]').select(xml).render()) |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
243 self.assertEqual('<item/><item important="notso"/>', |
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
244 Path('root/item[@important!="very"]').select(xml).render()) |
1 | 245 |
106
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
246 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
|
247 xml = XML('<root><item/><item important="very"/></root>') |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
248 path = Path('root/item[@important and @important="very"]') |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
249 self.assertEqual('<item important="very"/>', path.select(xml).render()) |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
250 path = Path('root/item[@important and @important="notso"]') |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
251 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
|
252 |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
253 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
|
254 xml = XML('<root><item/><item important="very"/></root>') |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
255 path = Path('root/item[@urgent or @important]') |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
256 self.assertEqual('<item important="very"/>', path.select(xml).render()) |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
257 path = Path('root/item[@urgent or @notso]') |
61fa4cadb766
Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents:
66
diff
changeset
|
258 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
|
259 |
1 | 260 |
261 def suite(): | |
262 suite = unittest.TestSuite() | |
111
8a4d9064f363
Some fixes and more unit tests for the XPath engine.
cmlenz
parents:
106
diff
changeset
|
263 suite.addTest(doctest.DocTestSuite(Path.__module__)) |
26
039fc5b87405
* Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents:
1
diff
changeset
|
264 suite.addTest(unittest.makeSuite(PathTestCase, 'test')) |
1 | 265 return suite |
266 | |
267 if __name__ == '__main__': | |
268 unittest.main(defaultTest='suite') |