Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LI - Lawful Interception
Trial
Commits
0c89bb7f
Commit
0c89bb7f
authored
Oct 22, 2021
by
canterburym
Browse files
Updating tests to include validation of instance documents
parent
111f14a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
103120/examples/FooServiceSchema.xsd
0 → 100644
View file @
0c89bb7f
<?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>
testing/check_xsd.py
View file @
0c89bb7f
...
...
@@ -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
(
'.x
ml
'
):
includeFileList
.
append
(
p
.
absolute
())
includeInstanceDocList
.
append
(
str
(
p
.
absolute
())
)
elif
str
(
p
.
absolute
()).
endswith
(
'.x
sd
'
):
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment