annotate markup/tests/path.py @ 128:396e54c94e11

Revert accidential checkin of unit test changes in [160].
author cmlenz
date Thu, 03 Aug 2006 17:21:11 +0000
parents c661dff3fd9f
children 38ddb21b6fa4
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):
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
27 self.assertRaises(PathSyntaxError, Path, 'parent::ma')
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
28
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
29 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
30 xml = XML('<root><elem/></root>')
fec9f4897415 Fix for #2 (incorrect context node in path expressions). Still some paths that produce incorrect results, but the common case seems to work now.
cmlenz
parents: 27
diff changeset
31 self.assertEqual('<elem/>', Path('elem').select(xml).render())
111
8a4d9064f363 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
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
33 self.assertEqual('<elem/>', Path('//elem').select(xml).render())
111
8a4d9064f363 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
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
35
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
36 def test_1step_self(self):
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
37 xml = XML('<root><elem/></root>')
61fa4cadb766 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
8a4d9064f363 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
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
40
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
41 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
42 xml = XML('<root><elem/></root>')
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
43 self.assertEqual('<elem/>', Path('*').select(xml).render())
111
8a4d9064f363 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
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
45 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
46
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
47 def test_1step_attribute(self):
111
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
48 self.assertEqual('', Path('@foo').select(XML('<root/>')).render())
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
49 xml = XML('<root foo="bar"/>')
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
50 self.assertEqual('bar', Path('@foo').select(xml).render())
8a4d9064f363 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
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
52
111
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
53 def test_1step_text(self):
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
54 xml = XML('<root>Hey</root>')
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
55 self.assertEqual('Hey', Path('text()').select(xml).render())
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
56 self.assertEqual('Hey', Path('./text()').select(xml).render())
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
57 self.assertEqual('Hey', Path('//text()').select(xml).render())
8a4d9064f363 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
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
59
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
60 def test_2step(self):
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
61 xml = XML('<root><foo/><bar/></root>')
111
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
62 self.assertEqual('<foo/><bar/>', Path('*').select(xml).render())
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
63 self.assertEqual('<bar/>', Path('bar').select(xml).render())
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
64 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
65
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
66 def test_2step_complex(self):
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
67 xml = XML('<root><foo><bar/></foo></root>')
039fc5b87405 * 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())
039fc5b87405 * 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())
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
70
039fc5b87405 * 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>')
128
396e54c94e11 Revert accidential checkin of unit test changes in [160].
cmlenz
parents: 126
diff changeset
72 self.assertEqual('<bar id="1"/><bar id="2"/>',
396e54c94e11 Revert accidential checkin of unit test changes in [160].
cmlenz
parents: 126
diff changeset
73 Path('bar').select(xml).render())
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
74
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
75 def test_2step_text(self):
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
76 xml = XML('<root><item>Foo</item></root>')
039fc5b87405 * 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
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
78 self.assertEqual('Foo', Path('*/text()').select(xml).render())
8a4d9064f363 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
039fc5b87405 * 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>')
039fc5b87405 * 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())
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
82
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
83 def test_3step(self):
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
84 xml = XML('<root><foo><bar/></foo></root>')
039fc5b87405 * 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())
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
86
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
87 def test_3step_complex(self):
039fc5b87405 * 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
61fa4cadb766 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
039fc5b87405 * 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>')
039fc5b87405 * 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
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
92 Path('//bar').select(xml).render())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
93
61fa4cadb766 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):
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
95 xml = XML('<root><!-- commented --></root>')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
96 self.assertEqual('<!-- commented -->',
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
97 Path('comment()').select(xml).render())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
98
61fa4cadb766 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):
61fa4cadb766 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>')
61fa4cadb766 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.',
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
102 Path('text()').select(xml).render())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
103
61fa4cadb766 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):
61fa4cadb766 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
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
106 self.assertEqual('Some text <br/>in here.',
106
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
107 Path('node()').select(xml).render())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
108
61fa4cadb766 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):
61fa4cadb766 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>')
61fa4cadb766 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") ?>',
61fa4cadb766 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())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
113 self.assertEqual('<?php echo("x") ?>',
61fa4cadb766 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())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
115
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
116 def test_simple_union(self):
61fa4cadb766 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>')
61fa4cadb766 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>',
61fa4cadb766 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
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
120
121
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
121 def test_predicate_name(self):
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
122 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
123 self.assertEqual('<foo/>',
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
124 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
125
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
126 def test_predicate_localname(self):
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
127 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
128 self.assertEqual('<foo xmlns="NS"/>',
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
129 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
130
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
131 def test_predicate_namespace(self):
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
132 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
133 self.assertEqual('<foo xmlns="NS"/>',
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
134 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
135
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
136 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
137 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
138 self.assertEqual('<bar/>',
22a7080ed242 Added support for the XPath functions `name()`, `namespace-uri()`, `local-name()`, and `not()`.
cmlenz
parents: 111
diff changeset
139 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
140
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
141 def test_predicate_attr(self):
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
142 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
143 self.assertEqual('<item important="very"/>',
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
144 Path('root/item[@important]').select(xml).render())
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
145 self.assertEqual('<item important="very"/>',
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
146 Path('root/item[@important="very"]').select(xml).render())
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
147
106
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
148 def test_predicate_attr_equality(self):
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
149 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
150 self.assertEqual('',
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
151 Path('root/item[@important="very"]').select(xml).render())
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
152 self.assertEqual('<item/><item important="notso"/>',
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
153 Path('root/item[@important!="very"]').select(xml).render())
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
154
106
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
155 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
156 xml = XML('<root><item/><item important="very"/></root>')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
157 path = Path('root/item[@important and @important="very"]')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
158 self.assertEqual('<item important="very"/>', path.select(xml).render())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
159 path = Path('root/item[@important and @important="notso"]')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
160 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
161
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
162 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
163 xml = XML('<root><item/><item important="very"/></root>')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
164 path = Path('root/item[@urgent or @important]')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
165 self.assertEqual('<item important="very"/>', path.select(xml).render())
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
166 path = Path('root/item[@urgent or @notso]')
61fa4cadb766 Complete rewrite of the XPath parsing, which was a mess before. Closes #19.
cmlenz
parents: 66
diff changeset
167 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
168
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
169
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
170 def suite():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
171 suite = unittest.TestSuite()
111
8a4d9064f363 Some fixes and more unit tests for the XPath engine.
cmlenz
parents: 106
diff changeset
172 suite.addTest(doctest.DocTestSuite(Path.__module__))
26
039fc5b87405 * Split out the XPath tests into a separate `unittest`-based file.
cmlenz
parents: 1
diff changeset
173 suite.addTest(unittest.makeSuite(PathTestCase, 'test'))
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
174 return suite
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
175
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
176 if __name__ == '__main__':
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
177 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software