Commit 0c89bb7f authored by canterburym's avatar canterburym
Browse files

Updating tests to include validation of instance documents

parent 111f14a0
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://FooServiceSchema.example.com/schema/v1.1.1/"
elementFormDefault="qualified"
xmlns="http://FooServiceSchema.example.com/schema/v1.1.1/"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="FooItem" type="FooItem"></xs:element>
<xs:complexType name="FooItem">
<xs:sequence>
<xs:element name="item1" type="ItemType"></xs:element>
<xs:element name="item2" type="ItemType"></xs:element>
<xs:element name="item3" type="ItemType"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="ItemType">
<xs:restriction base="xs:string">
<xs:enumeration value="Foo"></xs:enumeration>
<xs:enumeration value="Bar"></xs:enumeration>
<xs:enumeration value="Baz"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
......@@ -92,6 +92,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbosity", help="verbosity level", action="count", default=0)
parser.add_argument("input", help="include a directory or file", action="append", nargs="+")
parser.add_argument("-p", "--primaryNamespace", help="Primary schema namespace for instance doc validation")
args = parser.parse_args()
logging.getLogger().setLevel(logging.WARNING)
......@@ -101,6 +102,7 @@ if __name__ == '__main__':
logging.getLogger().setLevel(logging.DEBUG)
logging.debug("Very verbose selected")
logging.debug(f"Path: {args.input}")
includeFileList = []
includeInstanceDocList = []
......@@ -118,14 +120,18 @@ if __name__ == '__main__':
logging.info(f">Including instance doc {g}")
includeInstanceDocList.append(g)
else:
logging.info(f"Including {p.absolute()}")
logging.info(f">Including {p.absolute()}")
if str(p.absolute()).endswith('.xml'):
includeInstanceDocList.append(p.absolute())
elif str(p.absolute()).endswith('.xml'):
includeFileList.append(p.absolute())
includeInstanceDocList.append(str(p.absolute()))
elif str(p.absolute()).endswith('.xsd'):
includeFileList.append(str(p.absolute()))
else:
logging.warning(f'Ignoring file {p.absolute()}')
if len(includeInstanceDocList) and (args.primaryNamespace is None):
print("Cannot validate instance documents without specifying a primary namespace (use -h for usage guidelines)")
exit(-1)
syntaxErrors = 0
print ("XSD syntax checks:")
......@@ -169,6 +175,15 @@ if __name__ == '__main__':
print ("-----------------------------")
errorCount = 0
primarySchema = schemaDict[args.primaryNamespace]
for instanceDoc in includeInstanceDocList:
print (f" {instanceDoc:}")
try:
results = primarySchema.validate(instanceDoc)
print (f" {instanceDoc} : OK")
except Exception as ex:
errorCount += 1
print (f" {instanceDoc} : {str(ex)}")
print (f"{errorCount} instance doc errors detected")
exit(errorCount)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment