def test_xmlschema_proxy(self): context = XPathContext(root=self.etree.XML( '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/>')) self.wrong_syntax("schema-element(*)") self.wrong_name("schema-element(nil)") self.wrong_name("schema-element(xs:string)") self.check_value("schema-element(xs:complexType)", MissingContextError) self.check_value("self::schema-element(xs:complexType)", NameError, context) self.check_value("self::schema-element(xs:schema)", [context.item], context) self.check_tree("schema-element(xs:group)", '(schema-element (: (xs) (group)))') attribute = context.item = AttributeNode(XML_LANG, 'en') self.wrong_syntax("schema-attribute(*)") self.wrong_name("schema-attribute(nil)") self.wrong_name("schema-attribute(xs:string)") self.check_value("schema-attribute(xml:lang)", MissingContextError) self.check_value("schema-attribute(xml:lang)", NameError, context) self.check_value("self::schema-attribute(xml:lang)", [context.item], context) self.check_tree("schema-attribute(xsi:schemaLocation)", '(schema-attribute (: (xsi) (schemaLocation)))') token = self.parser.parse("self::schema-attribute(xml:lang)") context.item = attribute context.axis = 'attribute' self.assertEqual(list(token.select(context)), [context.item])
def test_is_principal_node_kind(self): root = ElementTree.XML('<A a1="10" a2="20"/>') context = XPathContext(root) self.assertTrue(hasattr(context.item.elem, 'tag')) self.assertTrue(context.is_principal_node_kind()) context.item = context.root.attributes[0] self.assertFalse(context.is_principal_node_kind()) context.axis = 'attribute' self.assertTrue(context.is_principal_node_kind())