comparison genshi/tests/path.py @ 1045:d7ede0cf4735 stable-0.6.x tip

Merge r1269 from trunk (fix for selecting namespaced attributes).
author hodgestar
date Thu, 20 Mar 2014 13:01:56 +0000
parents f91289c7d092
children
comparison
equal deleted inserted replaced
1042:63c0a3911ab8 1045:d7ede0cf4735
12 # history and logs, available at http://genshi.edgewall.org/log/. 12 # history and logs, available at http://genshi.edgewall.org/log/.
13 13
14 import doctest 14 import doctest
15 import unittest 15 import unittest
16 16
17 from genshi.core import Attrs, QName
17 from genshi.input import XML 18 from genshi.input import XML
18 from genshi.path import Path, PathParser, PathSyntaxError, GenericStrategy, \ 19 from genshi.path import Path, PathParser, PathSyntaxError, GenericStrategy, \
19 SingleStepStrategy, SimplePathStrategy 20 SingleStepStrategy, SimplePathStrategy
20 21
21 22
628 '/descendant::c', input=xml, output='<c>!</c>') 629 '/descendant::c', input=xml, output='<c>!</c>')
629 self._test_eval('//d/descendant::b/descendant::b/descendant::b' 630 self._test_eval('//d/descendant::b/descendant::b/descendant::b'
630 '/descendant::b/descendant::c', input=xml, 631 '/descendant::b/descendant::c', input=xml,
631 output='') 632 output='')
632 633
634 def test_attr_selection(self):
635 xml = XML('<root><foo bar="abc"></foo></root>')
636 path = Path('foo/@bar')
637 result = path.select(xml)
638 self.assertEqual(list(result), [
639 Attrs([(QName('bar'), u'abc')])
640 ])
641
642 def test_attr_selection_with_namespace(self):
643 xml = XML(
644 '<root xmlns:ns1="http://example.com">'
645 '<foo ns1:bar="abc"></foo>'
646 '</root>')
647 path = Path('foo/@ns1:bar')
648 result = path.select(xml, namespaces={'ns1': 'http://example.com'})
649 self.assertEqual(list(result), [
650 Attrs([(QName('http://example.com}bar'), u'abc')])
651 ])
652
633 def _test_support(self, strategy_class, text): 653 def _test_support(self, strategy_class, text):
634 path = PathParser(text, None, -1).parse()[0] 654 path = PathParser(text, None, -1).parse()[0]
635 return strategy_class.supports(path) 655 return strategy_class.supports(path)
636 656
637 def test_simple_strategy_support(self): 657 def test_simple_strategy_support(self):
Copyright (C) 2012-2017 Edgewall Software