Loading testing/check_xsd.py +46 −14 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ import os from lxml import etree from xml.etree.ElementTree import ParseError from xmlschema import XMLSchema, XMLSchemaParseError from xmlschema.validators.exceptions import XMLSchemaModelError def BuildSchemaDictonary (fileList): Loading Loading @@ -60,7 +61,7 @@ def ValidateXSDFiles (fileList): schema = XMLSchema(schemaFile, locations = schemaLocations) logging.info(schemaFile + ": OK") errors[schemaFile] = [] except XMLSchemaParseError as ex: except (XMLSchemaParseError, XMLSchemaModelError) as ex: if (ex.schema_url) and (ex.schema_url != ex.origin_url): logging.info(" Error {1} comes from {0}, suppressing".format(ex.schema_url, ex.message)) errors[schemaFile] = [] Loading Loading @@ -90,6 +91,8 @@ def ValidateInstanceDocuments (coreFile, supportingSchemas, instanceDocs): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbosity", help="verbosity level", action="count", default=0) parser.add_argument("-r", "--recurse", help="recurse into subdirectories", action="store_true") parser.add_argument("-s", "--skipbuild", help="skip the (lengthy) build checks", action="store_true") parser.add_argument("input", help="include a directory or file", action="append", nargs="+") args = parser.parse_args() Loading @@ -101,6 +104,12 @@ if __name__ == '__main__': logging.debug("Very verbose selected") logging.debug(f"Path: {args.input}") if (args.recurse): logging.info ("Recursion enabled") if (args.skipbuild): logging.info("Skipping build checks") includeFileList = [] for path in args.input[0]: p = Path(path) Loading @@ -109,34 +118,47 @@ if __name__ == '__main__': exit(1) if p.is_dir(): logging.debug(f"Expanding directory") for g in glob.glob(os.path.join(str(p), "*.xsd")): logging.info(f">Including {g}") includeFileList.append(g) if (args.recurse): files = p.rglob("*.xsd") else: files = p.glob("*.xsd") for f in files: logging.info(f"...Including {f}") includeFileList.append(str(f.absolute())) else: logging.info(f"Including {p.absolute()}") includeFileList.append(p.absolute()) includeFileList.append(str(p.absolute())) syntaxErrors = 0 print ("====================================================") print ("XSD syntax checks:") print ("-----------------------------") print ("----------------------------------------------------") errors = {} for file in includeFileList: error = ValidateSingleFile(file) if (error): print (f" {file} : Syntax error [{error}]") syntaxErrors += 1 errors[file] = error else: print (f" {file} : OK") print ("-----------------------------") if (syntaxErrors > 0): print ("----------------------------------------------------") print (f"{syntaxErrors} syntax errors detected") if (len(errors.keys()) > 0): for fileName, error in errors.items(): print(f" {fileName}: {error}") exit(syntaxErrors) results = ValidateXSDFiles(includeFileList) if (args.skipbuild): print ("Skipping build checks") exit(0) print ("XSD build checks:") print ("-----------------------------") print ("") print ("====================================================") print ("XSD build checks (this may take a while):") print ("----------------------------------------------------") results = ValidateXSDFiles(includeFileList) errorCount = 0 for fileName, errors in results.items(): if len(errors) > 0: Loading @@ -150,6 +172,16 @@ if __name__ == '__main__': else: print (f" {fileName}: OK") print ("-----------------------------") print ("----------------------------------------------------") print (f"{errorCount} build errors detected") for fileName, errors in results.items(): if len(errors) > 0: errorCount += len(errors) print (f" {fileName}: {len(errors)} errors") for error in errors: if isinstance(error, XMLSchemaParseError): print (str(error)) else: print (f" {str(error.strip())}") exit(errorCount) No newline at end of file Loading
testing/check_xsd.py +46 −14 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ import os from lxml import etree from xml.etree.ElementTree import ParseError from xmlschema import XMLSchema, XMLSchemaParseError from xmlschema.validators.exceptions import XMLSchemaModelError def BuildSchemaDictonary (fileList): Loading Loading @@ -60,7 +61,7 @@ def ValidateXSDFiles (fileList): schema = XMLSchema(schemaFile, locations = schemaLocations) logging.info(schemaFile + ": OK") errors[schemaFile] = [] except XMLSchemaParseError as ex: except (XMLSchemaParseError, XMLSchemaModelError) as ex: if (ex.schema_url) and (ex.schema_url != ex.origin_url): logging.info(" Error {1} comes from {0}, suppressing".format(ex.schema_url, ex.message)) errors[schemaFile] = [] Loading Loading @@ -90,6 +91,8 @@ def ValidateInstanceDocuments (coreFile, supportingSchemas, instanceDocs): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbosity", help="verbosity level", action="count", default=0) parser.add_argument("-r", "--recurse", help="recurse into subdirectories", action="store_true") parser.add_argument("-s", "--skipbuild", help="skip the (lengthy) build checks", action="store_true") parser.add_argument("input", help="include a directory or file", action="append", nargs="+") args = parser.parse_args() Loading @@ -101,6 +104,12 @@ if __name__ == '__main__': logging.debug("Very verbose selected") logging.debug(f"Path: {args.input}") if (args.recurse): logging.info ("Recursion enabled") if (args.skipbuild): logging.info("Skipping build checks") includeFileList = [] for path in args.input[0]: p = Path(path) Loading @@ -109,34 +118,47 @@ if __name__ == '__main__': exit(1) if p.is_dir(): logging.debug(f"Expanding directory") for g in glob.glob(os.path.join(str(p), "*.xsd")): logging.info(f">Including {g}") includeFileList.append(g) if (args.recurse): files = p.rglob("*.xsd") else: files = p.glob("*.xsd") for f in files: logging.info(f"...Including {f}") includeFileList.append(str(f.absolute())) else: logging.info(f"Including {p.absolute()}") includeFileList.append(p.absolute()) includeFileList.append(str(p.absolute())) syntaxErrors = 0 print ("====================================================") print ("XSD syntax checks:") print ("-----------------------------") print ("----------------------------------------------------") errors = {} for file in includeFileList: error = ValidateSingleFile(file) if (error): print (f" {file} : Syntax error [{error}]") syntaxErrors += 1 errors[file] = error else: print (f" {file} : OK") print ("-----------------------------") if (syntaxErrors > 0): print ("----------------------------------------------------") print (f"{syntaxErrors} syntax errors detected") if (len(errors.keys()) > 0): for fileName, error in errors.items(): print(f" {fileName}: {error}") exit(syntaxErrors) results = ValidateXSDFiles(includeFileList) if (args.skipbuild): print ("Skipping build checks") exit(0) print ("XSD build checks:") print ("-----------------------------") print ("") print ("====================================================") print ("XSD build checks (this may take a while):") print ("----------------------------------------------------") results = ValidateXSDFiles(includeFileList) errorCount = 0 for fileName, errors in results.items(): if len(errors) > 0: Loading @@ -150,6 +172,16 @@ if __name__ == '__main__': else: print (f" {fileName}: OK") print ("-----------------------------") print ("----------------------------------------------------") print (f"{errorCount} build errors detected") for fileName, errors in results.items(): if len(errors) > 0: errorCount += len(errors) print (f" {fileName}: {len(errors)} errors") for error in errors: if isinstance(error, XMLSchemaParseError): print (str(error)) else: print (f" {str(error.strip())}") exit(errorCount) No newline at end of file