コード例 #1
0
    def test_etree_element_method(self):
        converter = XMLSchemaConverter()
        elem = converter.etree_element('A')
        self.assertIsNone(etree_elements_assert_equal(elem, etree_element('A')))

        elem = converter.etree_element('A', attrib={})
        self.assertIsNone(etree_elements_assert_equal(elem, etree_element('A')))
コード例 #2
0
    def test_prefix_arguments(self):
        converter = XMLSchemaConverter(cdata_prefix='#')
        self.assertEqual(converter.cdata_prefix, '#')

        converter = XMLSchemaConverter(attr_prefix='%')
        self.assertEqual(converter.attr_prefix, '%')

        with self.assertRaises(ValueError):
            XMLSchemaConverter(attr_prefix='_')
コード例 #3
0
    def test_element_class_argument(self):
        converter = XMLSchemaConverter()
        self.assertIs(converter.etree_element_class, etree_element)

        converter = XMLSchemaConverter(etree_element_class=etree_element)
        self.assertIs(converter.etree_element_class, etree_element)

        if lxml_etree_element is not None:
            converter = XMLSchemaConverter(
                etree_element_class=lxml_etree_element)
            self.assertIs(converter.etree_element_class, lxml_etree_element)
コード例 #4
0
    def test_prefix_arguments(self):
        converter = XMLSchemaConverter(cdata_prefix='#')
        self.assertEqual(converter.cdata_prefix, '#')

        converter = XMLSchemaConverter(attr_prefix='%')
        self.assertEqual(converter.attr_prefix, '%')

        converter = XMLSchemaConverter(attr_prefix='_')
        self.assertEqual(converter.attr_prefix, '_')

        converter = XMLSchemaConverter(attr_prefix='attribute__')
        self.assertEqual(converter.attr_prefix, 'attribute__')

        converter = XMLSchemaConverter(text_key='text__')
        self.assertEqual(converter.text_key, 'text__')
コード例 #5
0
    def test_element_class_argument(self):
        converter = XMLSchemaConverter()
        self.assertIs(converter.etree_element_class, etree_element)
        self.assertIs(converter.register_namespace, etree_register_namespace)

        converter = XMLSchemaConverter(etree_element_class=etree_element)
        self.assertIs(converter.etree_element_class, etree_element)
        self.assertIs(converter.register_namespace, etree_register_namespace)

        if lxml_etree_element is not None:
            converter = XMLSchemaConverter(etree_element_class=lxml_etree_element)
            self.assertIs(converter.etree_element_class, lxml_etree_element)
            self.assertIs(converter.register_namespace, lxml_etree_register_namespace)

        with self.assertRaises(TypeError):
            XMLSchemaConverter(etree_element_class=ElementData)
コード例 #6
0
    def test_strip_namespace_argument(self):
        # Test for issue #161
        converter = XMLSchemaConverter(strip_namespaces=True)
        col_xsd_filename = self.casepath('examples/collection/collection.xsd')
        col_xml_filename = self.casepath('examples/collection/collection.xml')

        col_schema = XMLSchema(col_xsd_filename, converter=converter)
        self.assertIn('@xmlns:', str(col_schema.decode(col_xml_filename, strip_namespaces=False)))
        self.assertNotIn('@xmlns:', str(col_schema.decode(col_xml_filename)))
コード例 #7
0
 def test_lossy_property(self):
     self.assertTrue(XMLSchemaConverter().lossy)
     self.assertFalse(XMLSchemaConverter(cdata_prefix='#').lossy)