annotate markup/tests/path.py @ 118:c392d38694d9 trunk

Add basic support for using `lambda`s in expressions. Closes #21. (Not sure about default arguments, need a test case).
author cmlenz
date Tue, 01 Aug 2006 22:34:39 +0000
parents 2368c3becc52
children 062e51ad7b19
rev   line source
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
2 #
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 38
diff changeset
3 # Copyright (C) 2006 Edgewall Software
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
5 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 38
diff changeset
8 # are also available at http://markup.edgewall.org/wiki/License.
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
9 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 38
diff changeset
12 # history and logs, available at http://markup.edgewall.org/log/.
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
13
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
14 import doctest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
15 import unittest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
16
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
17 from markup.input import XML
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
18 from markup.path import Path, PathSyntaxError
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
19
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
20
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
21 class PathTestCase(unittest.TestCase):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
22
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
23 def test_error_no_absolute_path(self):
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
24 self.assertRaises(PathSyntaxError, Path, '/root')
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
25
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
26 def test_error_unsupported_axis(self):
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
27 self.assertRaises(PathSyntaxError, Path, 'parent::ma')
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
28
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
29 def test_1step(self):
38
ee669cb9cccc Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
30 xml = XML('<root><elem/></root>')
ee669cb9cccc Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
31 self.assertEqual('<elem/>', Path('elem').select(xml).render())
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
32 self.assertEqual('<elem/>', Path('child::elem').select(xml).render())
38
ee669cb9cccc Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
33 self.assertEqual('<elem/>', Path('//elem').select(xml).render())
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
34 self.assertEqual('<elem/>', Path('descendant::elem').select(xml).render())
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
35
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
36 def test_1step_self(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
37 xml = XML('<root><elem/></root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
38 self.assertEqual('<root><elem/></root>', Path('.').select(xml).render())
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
39 #self.assertEqual('<root><elem/></root>', Path('self::node()').select(xml).render())
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
40
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
41 def test_1step_wildcard(self):
38
ee669cb9cccc Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
42 xml = XML('<root><elem/></root>')
ee669cb9cccc Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
43 self.assertEqual('<elem/>', Path('*').select(xml).render())
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
44 self.assertEqual('<elem/>', Path('child::node()').select(xml).render())
38
ee669cb9cccc Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
45 self.assertEqual('<elem/>', Path('//*').select(xml).render())
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
46
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
47 def test_1step_attribute(self):
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
48 self.assertEqual('', Path('@foo').select(XML('<root/>')).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
49 xml = XML('<root foo="bar"/>')
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
50 self.assertEqual('bar', Path('@foo').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
51 self.assertEqual('bar', Path('./@foo').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
52
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
53 def test_1step_text(self):
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
54 xml = XML('<root>Hey</root>')
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
55 self.assertEqual('Hey', Path('text()').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
56 self.assertEqual('Hey', Path('./text()').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
57 self.assertEqual('Hey', Path('//text()').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
58 self.assertEqual('Hey', Path('.//text()').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
59
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
60 def test_2step(self):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
61 xml = XML('<root><foo/><bar/></root>')
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
62 self.assertEqual('<foo/><bar/>', Path('*').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
63 self.assertEqual('<bar/>', Path('bar').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
64 self.assertEqual('', Path('baz').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
65
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
66 def test_2step_complex(self):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
67 xml = XML('<root><foo><bar/></foo></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
68 self.assertEqual('<bar/>', Path('foo/bar').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
69 self.assertEqual('<bar/>', Path('foo/*').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
70
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
71 xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
72 self.assertEqual('<bar id="1"/><bar id="2"/>',
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
73 Path('bar').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
74
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
75 def test_2step_text(self):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
76 xml = XML('<root><item>Foo</item></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
77 self.assertEqual('Foo', Path('item/text()').select(xml).render())
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
78 self.assertEqual('Foo', Path('*/text()').select(xml).render())
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
79 self.assertEqual('Foo', Path('//text()').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
80 xml = XML('<root><item>Foo</item><item>Bar</item></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
81 self.assertEqual('FooBar', Path('item/text()').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
82
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
83 def test_3step(self):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
84 xml = XML('<root><foo><bar/></foo></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
85 self.assertEqual('<bar/>', Path('root/foo/*').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
86
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
87 def test_3step_complex(self):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
88 xml = XML('<root><foo><bar/></foo></root>')
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
89 self.assertEqual('<bar/>', Path('*/bar').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
90 xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
91 self.assertEqual('<bar id="1"/><bar id="2"/>',
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
92 Path('//bar').select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
93
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
94 def test_node_type_comment(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
95 xml = XML('<root><!-- commented --></root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
96 self.assertEqual('<!-- commented -->',
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
97 Path('comment()').select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
98
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
99 def test_node_type_text(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
100 xml = XML('<root>Some text <br/>in here.</root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
101 self.assertEqual('Some text in here.',
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
102 Path('text()').select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
103
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
104 def test_node_type_node(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
105 xml = XML('<root>Some text <br/>in here.</root>')
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
106 self.assertEqual('Some text <br/>in here.',
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
107 Path('node()').select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
108
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
109 def test_node_type_processing_instruction(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
110 xml = XML('<?python x = 2 * 3 ?><root><?php echo("x") ?></root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
111 self.assertEqual('<?python x = 2 * 3 ?><?php echo("x") ?>',
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
112 Path('processing-instruction()').select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
113 self.assertEqual('<?php echo("x") ?>',
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
114 Path('processing-instruction("php")').select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
115
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
116 def test_simple_union(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
117 xml = XML('<root>Oh <foo>my</foo></root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
118 self.assertEqual('Oh <foo>my</foo>',
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
119 Path('*|text()').select(xml).render())
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
120
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
121 def test_predicate_attr(self):
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
122 xml = XML('<root><item/><item important="very"/></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
123 self.assertEqual('<item important="very"/>',
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
124 Path('root/item[@important]').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
125 self.assertEqual('<item important="very"/>',
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
126 Path('root/item[@important="very"]').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
127
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
128 def test_predicate_attr_equality(self):
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
129 xml = XML('<root><item/><item important="notso"/></root>')
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
130 self.assertEqual('',
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
131 Path('root/item[@important="very"]').select(xml).render())
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
132 self.assertEqual('<item/><item important="notso"/>',
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
133 Path('root/item[@important!="very"]').select(xml).render())
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
134
106
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
135 def test_predicate_attr_and(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
136 xml = XML('<root><item/><item important="very"/></root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
137 path = Path('root/item[@important and @important="very"]')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
138 self.assertEqual('<item important="very"/>', path.select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
139 path = Path('root/item[@important and @important="notso"]')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
140 self.assertEqual('', path.select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
141
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
142 def test_predicate_attr_or(self):
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
143 xml = XML('<root><item/><item important="very"/></root>')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
144 path = Path('root/item[@urgent or @important]')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
145 self.assertEqual('<item important="very"/>', path.select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
146 path = Path('root/item[@urgent or @notso]')
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
147 self.assertEqual('', path.select(xml).render())
f9473bdc93b2 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
148
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
149
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
150 def suite():
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
151 suite = unittest.TestSuite()
111
2368c3becc52 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
152 suite.addTest(doctest.DocTestSuite(Path.__module__))
26
3c1a022be04c * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
153 suite.addTest(unittest.makeSuite(PathTestCase, 'test'))
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
154 return suite
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
155
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
156 if __name__ == '__main__':
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
157 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software