Mercurial > genshi > mirror
comparison genshi/tests/path.py @ 1044:ddb9354ad555 stable-0.7.x
Merge r1269 from trunk (fix for selecting namespaced attributes).
author | hodgestar |
---|---|
date | Thu, 20 Mar 2014 13:01:30 +0000 |
parents | f91289c7d092 |
children |
comparison
equal
deleted
inserted
replaced
1041:cddcb39ce5dd | 1044:ddb9354ad555 |
---|---|
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): |