def test_xml_document_decode_without_schema(self): xml_document = XmlDocument('<x:root xmlns:x="ns" />', validation='skip') self.assertIsNone(xml_document.decode()) xml_document = XmlDocument( '<x:root xmlns:x="ns" a="true"><b1>10</b1><b2/></x:root>', validation='skip') self.assertEqual(xml_document.decode(), { '@a': 'true', 'b1': ['10'], 'b2': [None] })
def test_xml_document_decode_with_xsi_type(self): xml_data = '<root xmlns:xsi="{}" xmlns:xs="{}" ' \ 'xsi:type="xs:integer">10</root>'.format(XSI_NAMESPACE, XSD_NAMESPACE) xml_document = XmlDocument(xml_data) self.assertEqual( xml_document.decode(), { '@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', '@xmlns:xs': 'http://www.w3.org/2001/XMLSchema', '@xsi:type': 'xs:integer', '$': 10 })
def test_xml_document_decode_with_schema(self): xml_document = XmlDocument(self.vh_xml_file) vh_schema = XMLSchema10(self.vh_xsd_file) self.assertEqual(xml_document.decode(), vh_schema.decode(self.vh_xml_file)) namespaces = {'vh': 'http://example.com/ns'} self.assertEqual( xml_document.decode(namespaces=namespaces), vh_schema.decode(self.vh_xml_file, namespaces=namespaces)) self.assertNotEqual(xml_document.decode(namespaces=namespaces), vh_schema.decode(self.vh_xml_file)) xml_file = casepath('examples/collection/collection-1_error.xml') xml_document = XmlDocument(xml_file, validation='lax') col_schema = XMLSchema10(self.col_xsd_file) self.assertEqual(xml_document.decode(), col_schema.decode(xml_file, validation='lax')[0]) xml_document = XmlDocument(xml_file, validation='skip') self.assertEqual(xml_document.decode(), col_schema.decode(xml_file, validation='skip')) self.assertEqual(xml_document.decode(validation='lax'), col_schema.decode(xml_file, validation='lax')[0])