Example #1
0
 def test_bind_parser_method(self):
     schema_proxy1 = XMLSchemaProxy(self.xs1)
     schema_proxy2 = XMLSchemaProxy(self.xs2)
     parser = XPath2Parser(strict=False, schema=schema_proxy1)
     self.assertIs(parser.schema, schema_proxy1)
     schema_proxy1.bind_parser(parser)
     self.assertIs(parser.schema, schema_proxy1)
     schema_proxy2.bind_parser(parser)
     self.assertIs(parser.schema, schema_proxy2)
    def test_bind_parser_method(self):
        schema_src = """<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
                            <xs:simpleType name="test_type">
                              <xs:restriction base="xs:string"/>
                            </xs:simpleType>
                        </xs:schema>"""
        schema = xmlschema.XMLSchema(schema_src)

        schema_proxy = XMLSchemaProxy(schema=schema)
        parser = XPath2Parser(namespaces=self.namespaces)
        schema_proxy.bind_parser(parser)
        self.assertIs(schema_proxy, parser.schema)
        parser = XPath2Parser(namespaces=self.namespaces)
        super(XMLSchemaProxy, schema_proxy).bind_parser(parser)
        self.assertIs(schema_proxy, parser.schema)
        super(XMLSchemaProxy, schema_proxy).bind_parser(parser)
        self.assertIs(schema_proxy, parser.schema)
    def test_bind_parser_method(self):
        schema_src = dedent("""
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
                <xs:simpleType name="stringType">
                    <xs:restriction base="xs:string"/>
                </xs:simpleType>
            </xs:schema>""")
        schema = xmlschema.XMLSchema(schema_src)

        schema_proxy = XMLSchemaProxy(schema=schema)
        parser = XPath2Parser(namespaces=self.namespaces)
        self.assertFalse(parser.is_schema_bound())

        schema_proxy.bind_parser(parser)
        self.assertTrue(parser.is_schema_bound())
        self.assertIs(schema_proxy, parser.schema)

        # To test AbstractSchemaProxy.bind_parser()
        parser = XPath2Parser(namespaces=self.namespaces)
        super(XMLSchemaProxy, schema_proxy).bind_parser(parser)
        self.assertIs(schema_proxy, parser.schema)
        super(XMLSchemaProxy, schema_proxy).bind_parser(parser)
        self.assertIs(schema_proxy, parser.schema)