def setUpClass(cls): cls.xsd_types = cls.schema_class.builtin_types() cls.content_pattern = re.compile(r'(xs:sequence|xs:choice|xs:all)') cls.default_namespaces = { 'ns': 'ns', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' } cls.vh_dir = cls.abspath('cases/examples/vehicles') cls.vh_xsd_file = cls.abspath('cases/examples/vehicles/vehicles.xsd') cls.vh_xml_file = cls.abspath('cases/examples/vehicles/vehicles.xml') cls.vh_json_file = cls.abspath('cases/examples/vehicles/vehicles.json') cls.vh_schema = cls.schema_class(cls.vh_xsd_file) cls.vh_namespaces = fetch_namespaces(cls.vh_xml_file) cls.col_dir = cls.abspath('cases/examples/collection') cls.col_xsd_file = cls.abspath( 'cases/examples/collection/collection.xsd') cls.col_xml_file = cls.abspath( 'cases/examples/collection/collection.xml') cls.col_json_file = cls.abspath( 'cases/examples/collection/collection.json') cls.col_schema = cls.schema_class(cls.col_xsd_file) cls.col_namespaces = fetch_namespaces(cls.col_xml_file) cls.st_xsd_file = cls.abspath( 'cases/features/decoder/simple-types.xsd') cls.st_schema = cls.schema_class(cls.st_xsd_file) cls.models_xsd_file = cls.abspath('cases/features/models/models.xsd') cls.models_schema = cls.schema_class(cls.models_xsd_file)
def setUpClass(cls): cls.errors = [] cls.xsd_types = cls.schema_class.builtin_types() cls.content_pattern = re.compile(r'(<|<xs:)(sequence|choice|all)') cls.default_namespaces = { 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'tns': 'http://xmlschema.test/ns', 'ns': 'ns', } if os.path.isfile(cls.casepath('testfiles')): cls.vh_dir = cls.casepath('examples/vehicles') cls.vh_xsd_file = cls.casepath('examples/vehicles/vehicles.xsd') cls.vh_xml_file = cls.casepath('examples/vehicles/vehicles.xml') cls.vh_json_file = cls.casepath('examples/vehicles/vehicles.json') cls.vh_schema = cls.schema_class(cls.vh_xsd_file) cls.vh_namespaces = fetch_namespaces(cls.vh_xml_file) cls.col_dir = cls.casepath('examples/collection') cls.col_xsd_file = cls.casepath( 'examples/collection/collection.xsd') cls.col_xml_file = cls.casepath( 'examples/collection/collection.xml') cls.col_json_file = cls.casepath( 'examples/collection/collection.json') cls.col_schema = cls.schema_class(cls.col_xsd_file) cls.col_namespaces = fetch_namespaces(cls.col_xml_file) cls.st_xsd_file = cls.casepath('features/decoder/simple-types.xsd') cls.st_schema = cls.schema_class(cls.st_xsd_file) cls.models_xsd_file = cls.casepath('features/models/models.xsd') cls.models_schema = cls.schema_class(cls.models_xsd_file)
def setUpClass(cls): cls.errors = [] cls.xsd_types = cls.schema_class.builtin_types() cls.content_pattern = re.compile(r'(xs:sequence|xs:choice|xs:all)') cls.default_namespaces = {'ns': 'ns', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'} cls.vh_dir = cls.casepath('examples/vehicles') cls.vh_xsd_file = cls.casepath('examples/vehicles/vehicles.xsd') cls.vh_xml_file = cls.casepath('examples/vehicles/vehicles.xml') cls.vh_json_file = cls.casepath('examples/vehicles/vehicles.json') cls.vh_schema = cls.schema_class(cls.vh_xsd_file) cls.vh_namespaces = fetch_namespaces(cls.vh_xml_file) cls.col_dir = cls.casepath('examples/collection') cls.col_xsd_file = cls.casepath('examples/collection/collection.xsd') cls.col_xml_file = cls.casepath('examples/collection/collection.xml') cls.col_json_file = cls.casepath('examples/collection/collection.json') cls.col_schema = cls.schema_class(cls.col_xsd_file) cls.col_namespaces = fetch_namespaces(cls.col_xml_file) cls.st_xsd_file = cls.casepath('features/decoder/simple-types.xsd') cls.st_schema = cls.schema_class(cls.st_xsd_file) cls.models_xsd_file = cls.casepath('features/models/models.xsd') cls.models_schema = cls.schema_class(cls.models_xsd_file)
def check_encoding_with_element_tree(self): root = ElementTree.parse(xml_file).getroot() namespaces = fetch_namespaces(xml_file) options = { 'namespaces': namespaces, 'dict_class': ordered_dict_class } self.check_etree_encode(root, cdata_prefix='#', **options) # Default converter self.check_etree_encode(root, ParkerConverter, validation='lax', **options) self.check_etree_encode(root, ParkerConverter, validation='skip', **options) self.check_etree_encode(root, BadgerFishConverter, **options) self.check_etree_encode(root, AbderaConverter, **options) self.check_etree_encode(root, JsonMLConverter, **options) options.pop('dict_class') self.check_json_serialization(root, cdata_prefix='#', **options) self.check_json_serialization(root, ParkerConverter, validation='lax', **options) self.check_json_serialization(root, ParkerConverter, validation='skip', **options) self.check_json_serialization(root, BadgerFishConverter, **options) self.check_json_serialization(root, AbderaConverter, **options) self.check_json_serialization(root, JsonMLConverter, **options)
def check_decoding_and_encoding_with_lxml(self): xml_tree = lxml_etree.parse(xml_file) namespaces = fetch_namespaces(xml_file) errors = [] chunks = [] for obj in self.schema.iter_decode(xml_tree, namespaces=namespaces): if isinstance(obj, xmlschema.XMLSchemaValidationError): errors.append(obj) else: chunks.append(obj) self.assertEqual(chunks, self.chunks, msg_tmpl % "decoded data change with lxml") self.assertEqual(len(errors), len(self.errors), msg_tmpl % "errors number change with lxml") if not errors: root = xml_tree.getroot() if namespaces.get(''): # Add a not empty prefix for encoding to avoid the use of reserved prefix ns0 namespaces['tns0'] = namespaces[''] options = { 'etree_element_class': lxml_etree_element, 'namespaces': namespaces, 'dict_class': ordered_dict_class, } self.check_etree_encode(root, cdata_prefix='#', **options) # Default converter self.check_etree_encode(root, ParkerConverter, validation='lax', **options) self.check_etree_encode(root, ParkerConverter, validation='skip', **options) self.check_etree_encode(root, BadgerFishConverter, **options) self.check_etree_encode(root, AbderaConverter, **options) self.check_etree_encode(root, JsonMLConverter, **options) options.pop('dict_class') self.check_json_serialization(root, cdata_prefix='#', **options) self.check_json_serialization(root, ParkerConverter, validation='lax', **options) self.check_json_serialization(root, ParkerConverter, validation='skip', **options) self.check_json_serialization(root, BadgerFishConverter, **options) self.check_json_serialization(root, AbderaConverter, **options) self.check_json_serialization(root, JsonMLConverter, **options)
def check_data_conversion_with_element_tree(self): root = ElementTree.parse(xml_file).getroot() namespaces = fetch_namespaces(xml_file) options = {'namespaces': namespaces} self.check_decode_encode(root, cdata_prefix='#', **options) # Default converter self.check_decode_encode(root, UnorderedConverter, cdata_prefix='#', **options) self.check_decode_encode(root, ParkerConverter, validation='lax', **options) self.check_decode_encode(root, ParkerConverter, validation='skip', **options) self.check_decode_encode(root, BadgerFishConverter, **options) self.check_decode_encode(root, AbderaConverter, **options) self.check_decode_encode(root, JsonMLConverter, **options) self.check_decode_encode(root, ColumnarConverter, validation='lax', **options) self.check_json_serialization(root, cdata_prefix='#', **options) self.check_json_serialization(root, UnorderedConverter, **options) self.check_json_serialization(root, ParkerConverter, validation='lax', **options) self.check_json_serialization(root, ParkerConverter, validation='skip', **options) self.check_json_serialization(root, BadgerFishConverter, **options) self.check_json_serialization(root, AbderaConverter, **options) self.check_json_serialization(root, JsonMLConverter, **options) self.check_json_serialization(root, ColumnarConverter, validation='lax', **options)