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