Ejemplo n.º 1
0
 def test_xpath_descendants(self):
     selector = Selector('.//xs:element', self.xs2.namespaces, parser=XPath1Parser)
     elements = list(selector.iter_select(self.xs2.root))
     self.assertEqual(len(elements), 14)
     selector = Selector('.//xs:element|.//xs:attribute|.//xs:keyref', self.xs2.namespaces, parser=XPath1Parser)
     elements = list(selector.iter_select(self.xs2.root))
     self.assertEqual(len(elements), 17)
Ejemplo n.º 2
0
    def test_selector_class(self):
        selector = Selector('/A')
        self.assertEqual(repr(selector),
                         "Selector(path='/A', parser=XPath2Parser)")
        self.assertEqual(selector.namespaces, XPath2Parser.DEFAULT_NAMESPACES)

        selector = Selector('text()')
        self.assertListEqual(selector.select(self.root), ['Dickens'])
        self.assertListEqual(list(selector.iter_select(self.root)),
                             ['Dickens'])

        selector = Selector('$a', variables={'a': 1})
        self.assertEqual(selector.select(self.root), 1)
        self.assertListEqual(list(selector.iter_select(self.root)), [1])