Mercurial > genshi > mirror
diff 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 |
line wrap: on
line diff
--- a/genshi/tests/path.py +++ b/genshi/tests/path.py @@ -14,6 +14,7 @@ import doctest import unittest +from genshi.core import Attrs, QName from genshi.input import XML from genshi.path import Path, PathParser, PathSyntaxError, GenericStrategy, \ SingleStepStrategy, SimplePathStrategy @@ -630,6 +631,25 @@ '/descendant::b/descendant::c', input=xml, output='') + def test_attr_selection(self): + xml = XML('<root><foo bar="abc"></foo></root>') + path = Path('foo/@bar') + result = path.select(xml) + self.assertEqual(list(result), [ + Attrs([(QName('bar'), u'abc')]) + ]) + + def test_attr_selection_with_namespace(self): + xml = XML( + '<root xmlns:ns1="http://example.com">' + '<foo ns1:bar="abc"></foo>' + '</root>') + path = Path('foo/@ns1:bar') + result = path.select(xml, namespaces={'ns1': 'http://example.com'}) + self.assertEqual(list(result), [ + Attrs([(QName('http://example.com}bar'), u'abc')]) + ]) + def _test_support(self, strategy_class, text): path = PathParser(text, None, -1).parse()[0] return strategy_class.supports(path)