def evaluate_xml_versus_schema(xml_string, urn_string): """ Check validity of the xml string versus the appropriate schema. Parameters ---------- xml_string : str|bytes urn_string : str Returns ------- bool """ # get schema path try: the_schema = get_schema_path(urn_string) except KeyError: logger.exception( 'SIDD: Failed finding the schema for urn {}'.format(urn_string)) return False try: return validate_xml_from_string(xml_string, the_schema, output_logger=logger) except ImportError: return None
def evaluate_xml_versus_schema(xml_string, urn_string): """ Check validity of the xml string versus the appropriate schema. Parameters ---------- xml_string : str urn_string : str Returns ------- bool """ if etree is None: return None # get schema path try: the_schema = get_schema_path(urn_string) except ValueError: logger.error('Failed finding the schema for urn {}'.format(urn_string)) return False xml_doc = etree.fromstring(xml_string) xml_schema = etree.XMLSchema(file=the_schema) validity = xml_schema.validate(xml_doc) if not validity: for entry in xml_schema.error_log: logger.error('SIDD schema validation error on line {}' '\n\t{}'.format(entry.line, entry.message.encode('utf-8'))) return validity
def test_sidd_creation(self): for fil in sicd_files: reader = SICDReader(fil) ortho_helper = NearestNeighborMethod(reader) # create a temp directory temp_directory = tempfile.mkdtemp() sidd_files = [] # create a basic sidd detected image with self.subTest( msg='Create version 1 detected image for file {}'.format( fil)): create_detected_image_sidd(ortho_helper, temp_directory, output_file='di_1.nitf', version=1) sidd_files.append('di_1.nitf') with self.subTest( msg='Create version 2 detected image for file {}'.format( fil)): create_detected_image_sidd(ortho_helper, temp_directory, output_file='di_2.nitf', version=2) sidd_files.append('di_2.nitf') # create a csi image with self.subTest( msg='Create version 1 csi for file {}'.format(fil)): create_csi_sidd(ortho_helper, temp_directory, output_file='csi_1.nitf', version=1) sidd_files.append('csi_1.nitf') with self.subTest( msg='Create version 2 csi for file {}'.format(fil)): create_csi_sidd(ortho_helper, temp_directory, output_file='csi_2.nitf', version=2) sidd_files.append('csi_2.nitf') # create a dynamic image with self.subTest( msg='Create version 1 subaperture stack for file {}'. format(fil)): create_dynamic_image_sidd(ortho_helper, temp_directory, output_file='sast_1.nitf', version=1, frame_count=3) sidd_files.append('sast_1.nitf') with self.subTest( msg='Create version 2 subaperture stack for file {}'. format(fil)): create_dynamic_image_sidd(ortho_helper, temp_directory, output_file='sast_2.nitf', version=2, frame_count=3) sidd_files.append('sast_2.nitf') # check that each sidd structure serialized according to the schema if etree is not None: for vers in [1, 2]: schema = get_schema_path('urn:SIDD:{}.0.0'.format(vers)) the_fil = 'di_{}.nitf'.format(vers) if the_fil in sidd_files: self.assertTrue( check_versus_schema( os.path.join(temp_directory, the_fil), schema), 'Detected image version {} structure not valid versus schema {}' .format(vers, schema)) the_fil = 'csi_{}.nitf'.format(vers) if the_fil in sidd_files: self.assertTrue( check_versus_schema( os.path.join(temp_directory, the_fil), schema), 'csi version {} structure not valid versus schema {}' .format(vers, schema)) the_fil = 'sast_{}.nitf'.format(vers) if the_fil in sidd_files: self.assertTrue( check_versus_schema( os.path.join(temp_directory, the_fil), schema), 'Dynamic image version {} structure not valid versus schema {}' .format(vers, schema)) # clean up the temporary directory shutil.rmtree(temp_directory)