comparison markup/tests/path.py @ 228:a5b38b459cbb trunk

Add support for position predicates in XPath expressions.
author cmlenz
date Fri, 08 Sep 2006 10:51:14 +0000
parents 90d62225f411
children
comparison
equal deleted inserted replaced
227:96a7e5011c69 228:a5b38b459cbb
25 25
26 def test_error_unsupported_axis(self): 26 def test_error_unsupported_axis(self):
27 self.assertRaises(PathSyntaxError, Path, '..') 27 self.assertRaises(PathSyntaxError, Path, '..')
28 self.assertRaises(PathSyntaxError, Path, 'parent::ma') 28 self.assertRaises(PathSyntaxError, Path, 'parent::ma')
29 29
30 def test_error_position_predicate(self):
31 self.assertRaises(PathSyntaxError, Path, 'item[0]')
32
33 def test_1step(self): 30 def test_1step(self):
34 xml = XML('<root><elem/></root>') 31 xml = XML('<root><elem/></root>')
35 32
36 path = Path('elem') 33 path = Path('elem')
37 self.assertEqual('<Path "child::elem">', repr(path)) 34 self.assertEqual('<Path "child::elem">', repr(path))
404 xml = XML('<root><foo>bar</foo></root>') 401 xml = XML('<root><foo>bar</foo></root>')
405 path = Path('*[name()=$bar]') 402 path = Path('*[name()=$bar]')
406 variables = {'bar': 'foo'} 403 variables = {'bar': 'foo'}
407 self.assertEqual('<foo>bar</foo>', 404 self.assertEqual('<foo>bar</foo>',
408 path.select(xml, variables=variables).render()) 405 path.select(xml, variables=variables).render())
406
407 def test_predicate_position(self):
408 xml = XML('<root><foo id="a1"/><foo id="a2"/><foo id="a3"/></root>')
409 path = Path('*[2]')
410 self.assertEqual('<foo id="a2"/>', path.select(xml).render())
411
412 def test_predicate_attr_and_position(self):
413 xml = XML('<root><foo/><foo id="a1"/><foo id="a2"/></root>')
414 path = Path('*[@id][2]')
415 self.assertEqual('<foo id="a2"/>', path.select(xml).render())
416
417 def test_predicate_position_and_attr(self):
418 xml = XML('<root><foo/><foo id="a1"/><foo id="a2"/></root>')
419 path = Path('*[1][@id]')
420 self.assertEqual('', path.select(xml).render())
421 path = Path('*[2][@id]')
422 self.assertEqual('<foo id="a1"/>', path.select(xml).render())
409 423
410 def test_name_with_namespace(self): 424 def test_name_with_namespace(self):
411 xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>') 425 xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>')
412 path = Path('f:foo') 426 path = Path('f:foo')
413 self.assertEqual('<Path "child::f:foo">', repr(path)) 427 self.assertEqual('<Path "child::f:foo">', repr(path))
Copyright (C) 2012-2017 Edgewall Software