1818
1919import unittest
2020
21- from neuxml import xpath
22- from neuxml .xpath import ast , serialize
21+ from neuxml . xpath import ast
22+ from neuxml .xpath . core import parse , serialize
2323
2424
2525class ParseTest (unittest .TestCase ):
2626 def test_nametest_step (self ):
27- xp = xpath . parse ("""author""" )
27+ xp = parse ("""author""" )
2828 self .assertTrue (isinstance (xp , ast .Step ))
2929 self .assertTrue (xp .axis is None ) # or should this be 'child', the default?
3030 self .assertTrue (isinstance (xp .node_test , ast .NameTest ))
@@ -33,20 +33,20 @@ def test_nametest_step(self):
3333 self .assertEqual (0 , len (xp .predicates ))
3434
3535 def test_nodetype_step (self ):
36- xp = xpath . parse ("""text()""" )
36+ xp = parse ("""text()""" )
3737 self .assertTrue (isinstance (xp , ast .Step ))
3838 self .assertTrue (isinstance (xp .node_test , ast .NodeType ))
3939 self .assertEqual ("text" , xp .node_test .name )
4040
4141 def test_axis (self ):
42- xp = xpath . parse ("""ancestor::lib:book""" )
42+ xp = parse ("""ancestor::lib:book""" )
4343 self .assertTrue (isinstance (xp , ast .Step ))
4444 self .assertEqual ("ancestor" , xp .axis )
4545 self .assertEqual ("lib" , xp .node_test .prefix )
4646 self .assertEqual ("book" , xp .node_test .name )
4747
4848 def test_relative_path (self ):
49- xp = xpath . parse ("""book//author/first-name""" )
49+ xp = parse ("""book//author/first-name""" )
5050 self .assertTrue (isinstance (xp , ast .BinaryExpression ))
5151 self .assertTrue (isinstance (xp .left , ast .BinaryExpression ))
5252 self .assertEqual ("book" , xp .left .left .node_test .name )
@@ -56,19 +56,19 @@ def test_relative_path(self):
5656 self .assertEqual ("first-name" , xp .right .node_test .name )
5757
5858 def test_absolute_path (self ):
59- xp = xpath . parse ("""/book//author""" )
59+ xp = parse ("""/book//author""" )
6060 self .assertTrue (isinstance (xp , ast .AbsolutePath ))
6161 self .assertEqual ("/" , xp .op )
6262 self .assertEqual ("book" , xp .relative .left .node_test .name )
6363
6464 def test_step_predicate (self ):
65- xp = xpath . parse ("""book[author]""" )
65+ xp = parse ("""book[author]""" )
6666 self .assertEqual ("book" , xp .node_test .name )
6767 self .assertEqual (1 , len (xp .predicates ))
6868 self .assertEqual ("author" , xp .predicates [0 ].node_test .name )
6969
7070 def test_function (self ):
71- xp = xpath . parse ("""author[position() = 1]""" )
71+ xp = parse ("""author[position() = 1]""" )
7272 self .assertTrue (isinstance (xp .predicates [0 ], ast .BinaryExpression ))
7373 self .assertEqual ("=" , xp .predicates [0 ].op )
7474 self .assertTrue (isinstance (xp .predicates [0 ].left , ast .FunctionCall ))
@@ -77,7 +77,7 @@ def test_function(self):
7777 self .assertEqual (1 , xp .predicates [0 ].right )
7878
7979 def test_variable (self ):
80- xp = xpath . parse ("""title[substring-after(text(), $pre:separator) = "world"]""" )
80+ xp = parse ("""title[substring-after(text(), $pre:separator) = "world"]""" )
8181 self .assertEqual ("title" , xp .node_test .name )
8282 self .assertTrue (isinstance (xp .predicates [0 ], ast .BinaryExpression ))
8383 self .assertEqual ("=" , xp .predicates [0 ].op )
@@ -93,7 +93,7 @@ def test_variable(self):
9393 self .assertEqual (("pre" , "separator" ), xp .predicates [0 ].left .args [1 ].name )
9494
9595 def test_predicated_expression (self ):
96- xp = xpath . parse ("""(book or article)[author/last-name = "Jones"]""" )
96+ xp = parse ("""(book or article)[author/last-name = "Jones"]""" )
9797 self .assertTrue (isinstance (xp , ast .PredicatedExpression ))
9898 self .assertTrue (isinstance (xp .base , ast .BinaryExpression ))
9999 self .assertEqual ("book" , xp .base .left .node_test .name )
@@ -110,7 +110,7 @@ def test_predicated_expression(self):
110110 def test_lex_exceptions (self ):
111111 # http://www.w3.org/TR/xpath/#exprlex describes several unusual
112112 # lexing rules. Verify them here.
113- xp = xpath . parse ("""***""" )
113+ xp = parse ("""***""" )
114114 self .assertTrue (isinstance (xp , ast .BinaryExpression ))
115115 self .assertEqual ("*" , xp .op )
116116 self .assertTrue (isinstance (xp .left , ast .Step ))
@@ -120,7 +120,7 @@ def test_lex_exceptions(self):
120120 self .assertTrue (isinstance (xp .right .node_test , ast .NameTest ))
121121 self .assertEqual ("*" , xp .right .node_test .name )
122122
123- xp = xpath . parse ("""div div div""" )
123+ xp = parse ("""div div div""" )
124124 self .assertTrue (isinstance (xp , ast .BinaryExpression ))
125125 self .assertEqual ("div" , xp .op )
126126 self .assertTrue (isinstance (xp .left , ast .Step ))
@@ -130,12 +130,12 @@ def test_lex_exceptions(self):
130130 self .assertTrue (isinstance (xp .right .node_test , ast .NameTest ))
131131 self .assertEqual ("div" , xp .right .node_test .name )
132132
133- xp = xpath . parse ("""div:div""" )
133+ xp = parse ("""div:div""" )
134134 self .assertTrue (isinstance (xp , ast .Step ))
135135 self .assertEqual ("div" , xp .node_test .prefix )
136136 self .assertEqual ("div" , xp .node_test .name )
137137
138- xp = xpath . parse ("""node/node()""" )
138+ xp = parse ("""node/node()""" )
139139 self .assertTrue (isinstance (xp , ast .BinaryExpression ))
140140 self .assertEqual ("/" , xp .op )
141141 self .assertTrue (isinstance (xp .left , ast .Step ))
@@ -145,28 +145,28 @@ def test_lex_exceptions(self):
145145 self .assertTrue (isinstance (xp .right .node_test , ast .NodeType ))
146146 self .assertEqual ("node" , xp .right .node_test .name )
147147
148- xp = xpath . parse ("""boolean(boolean)""" )
148+ xp = parse ("""boolean(boolean)""" )
149149 self .assertTrue (isinstance (xp , ast .FunctionCall ))
150150 self .assertEqual ("boolean" , xp .name )
151151 self .assertEqual (1 , len (xp .args ))
152152 self .assertTrue (isinstance (xp .args [0 ], ast .Step ))
153153 self .assertEqual ("boolean" , xp .args [0 ].node_test .name )
154154
155- xp = xpath . parse ("""parent::parent/parent:parent""" )
155+ xp = parse ("""parent::parent/parent:parent""" )
156156 self .assertEqual ("parent" , xp .left .axis )
157157 self .assertEqual ("parent" , xp .left .node_test .name )
158158 self .assertEqual ("parent" , xp .right .node_test .prefix )
159159 self .assertEqual ("parent" , xp .right .node_test .name )
160160
161161 def test_syntax_error (self ):
162162 # try to parse invalid xpath and make sure we get an exception
163- self .assertRaises (RuntimeError , xpath . parse , """bogus-(""" )
164- self .assertRaises (RuntimeError , xpath . parse , """/bogus-(""" )
163+ self .assertRaises (RuntimeError , parse , """bogus-(""" )
164+ self .assertRaises (RuntimeError , parse , """/bogus-(""" )
165165
166166
167167class TestSerializeRoundTrip (unittest .TestCase ):
168168 def round_trip (self , xpath_str ):
169- xp = xpath . parse (xpath_str )
169+ xp = parse (xpath_str )
170170 self .assertEqual (xpath_str , serialize (xp ))
171171
172172 def test_nametest (self ):
0 commit comments