annotate markup/tests/path.py @ 224:e4dad1145f84

Implement support for namespace prefixes in XPath expressions.
author cmlenz
date Wed, 06 Sep 2006 14:39:50 +0000
parents 0a01371cecbc
children f79b20a50919
rev   line source
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
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
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
5 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
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
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
9 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
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
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
13
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
14 import doctest
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
15 import unittest
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
35
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
38 self.assertEqual('<elem/>', path.select(xml).render())
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
39
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
40 path = Path('child::elem')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
41 self.assertEqual('<Path "child::elem">', repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
42 self.assertEqual('<elem/>', path.select(xml).render())
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
43
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
44 path = Path('//elem')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
45 self.assertEqual('<Path "descendant-or-self::node()/child::elem">',
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
46 repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
47 self.assertEqual('<elem/>', path.select(xml).render())
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
48
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
49 path = Path('descendant::elem')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
50 self.assertEqual('<Path "descendant::elem">', repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
55
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
56 path = Path('.')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
57 self.assertEqual('<Path "self::node()">', repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
58 self.assertEqual('<root><elem/></root>', path.select(xml).render())
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
59
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
60 path = Path('self::node()')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
61 self.assertEqual('<Path "self::node()">', repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
66
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
69 self.assertEqual('<elem/>', path.select(xml).render())
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
70
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
71 path = Path('child::*')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
72 self.assertEqual('<Path "child::*">', repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
73 self.assertEqual('<elem/>', path.select(xml).render())
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
74
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
75 path = Path('child::node()')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
78
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
79 path = Path('//*')
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
80 self.assertEqual('<Path "descendant-or-self::node()/child::*">',
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
81 repr(path))
38ddb21b6fa4 Further cleanup of XPath engine.
cmlenz
parents: 128
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
85 path = Path('@foo')
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
92 self.assertEqual('bar', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
93
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
94 path = Path('./@foo')
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
100
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
103 self.assertEqual('Hey', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
104
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
105 path = Path('./text()')
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
106 self.assertEqual('<Path "self::node()/child::text()">', repr(path))
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
107 self.assertEqual('Hey', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
108
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
109 path = Path('//text()')
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
110 self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
111 repr(path))
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
112 self.assertEqual('Hey', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
113
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
114 path = Path('.//text()')
215
e92135672812 A couple of minor XPath fixes.
cmlenz
parents: 179
diff changeset
115 self.assertEqual('<Path "self::node()/descendant-or-self::node()/child::text()">',
e92135672812 A couple of minor XPath fixes.
cmlenz
parents: 179
diff changeset
116 repr(path))
138
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
e92135672812 A couple of minor XPath fixes.
cmlenz
parents: 179
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
138
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
141 self.assertEqual('<bar/>', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
158
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
161 self.assertEqual('Foo', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
162
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
165 self.assertEqual('Foo', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
166
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
167 path = Path('//text()')
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
168 self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
169 repr(path))
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
170 self.assertEqual('Foo', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
188 repr(path))
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
195 self.assertEqual('<bar/>', path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
198 path = Path('//bar')
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
199 self.assertEqual('<Path "descendant-or-self::node()/child::bar">',
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
224
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
229 path.select(xml).render())
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
230
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
233 repr(path))
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
240 repr(path))
d91e1e822969 Add some more assertions to the XPath tests.
cmlenz
parents: 137
diff changeset
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
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
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'}
224
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
407 self.assertEqual('<foo>bar</foo>',
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
408 path.select(xml, variables=variables).render())
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
409
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
410 def test_name_with_namespace(self):
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
411 xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
412 path = Path('f:foo')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
413 self.assertEqual('<Path "child::f:foo">', repr(path))
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
414 namespaces = {'f': 'FOO'}
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
415 self.assertEqual('<foo xmlns="FOO">bar</foo>',
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
416 path.select(xml, namespaces=namespaces).render())
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
417
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
418 def test_wildcard_with_namespace(self):
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
419 xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
420 path = Path('f:*')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
421 self.assertEqual('<Path "child::f:*">', repr(path))
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
422 namespaces = {'f': 'FOO'}
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
423 self.assertEqual('<foo xmlns="FOO">bar</foo>',
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
424 path.select(xml, namespaces=namespaces).render())
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
425
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
426 # FIXME: the following two don't work due to a problem in XML serialization:
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
427 # attributes that would need a namespace prefix that isn't in the
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
428 # prefix map would need to get an artificial prefix, but currently
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
429 # don't
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
430 #
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
431 #def test_attrname_with_namespace(self):
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
432 # xml = XML('<root xmlns:f="FOO"><foo f:bar="baz"/></root>')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
433 # path = Path('foo[@f:bar]')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
434 # print path
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
435 # namespaces = {'f': 'FOO'}
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
436 # self.assertEqual('<foo f:bar="baz" xmlns="FOO"/>',
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
437 # path.select(xml, namespaces=namespaces).render())
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
438 #
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
439 #def test_attrwildcard_with_namespace(self):
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
440 # xml = XML('<root xmlns:f="FOO"><foo f:bar="baz"/></root>')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
441 # path = Path('foo[@f:*]')
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
442 # namespaces = {'f': 'FOO'}
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
443 # self.assertEqual('<foo f:bar="baz" xmlns="FOO"/>',
e4dad1145f84 Implement support for namespace prefixes in XPath expressions.
cmlenz
parents: 216
diff changeset
444 # path.select(xml, namespaces=namespaces).render())
179
a2e0a7986d19 Implemented support for XPath variables in predicates (#31).
cmlenz
parents: 164
diff changeset
445
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
446
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
447 def suite():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
448 suite = unittest.TestSuite()
111
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
449 suite.addTest(doctest.DocTestSuite(Path.__module__))
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
450 suite.addTest(unittest.makeSuite(PathTestCase, 'test'))
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
451 return suite
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
452
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
453 if __name__ == '__main__':
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
454 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software