@@ -91,7 +91,7 @@ def prepare_test(self):
91
91
if 'config' in self .config :
92
92
for option in self .config ['config' ]:
93
93
print (option , file = f )
94
- if (self .args .xml ):
94
+ if (self .args .xml or self . args . xmlxsd ):
95
95
print ('GENERATE_XML=YES' , file = f )
96
96
print ('XML_OUTPUT=%s/out' % self .test_out , file = f )
97
97
else :
@@ -182,11 +182,13 @@ def perform_test(self,testmgr):
182
182
failed_latex = False
183
183
failed_docbook = False
184
184
failed_rtf = False
185
+ failed_xmlxsd = False
185
186
msg = ()
186
187
# look for files to check against the reference
187
- if self .args .xml :
188
- failed_xml = True
189
- if 'check' in self .config :
188
+ if self .args .xml or self .args .xmlxsd :
189
+ failed_xml = False
190
+ if 'check' in self .config and self .args .xml :
191
+ failed_xml = True
190
192
for check in self .config ['check' ]:
191
193
check_file = '%s/out/%s' % (self .test_out ,check )
192
194
# check if the file we need to check is actually generated
@@ -215,9 +217,62 @@ def perform_test(self,testmgr):
215
217
if failed_xml :
216
218
msg += (xml_msg ,)
217
219
break
218
- if not failed_xml and not self .args .keep :
219
- xml_output = '%s/out' % self .test_out
220
- shutil .rmtree (xml_output ,ignore_errors = True )
220
+ failed_xmlxsd = False
221
+ if self .args .xmlxsd :
222
+ xmlxsd_output = '%s/out' % self .test_out
223
+ if (sys .platform == 'win32' ):
224
+ redirx = ' 2> %s/temp >nul:' % xmlxsd_output
225
+ else :
226
+ redirx = '2>%s/temp >/dev/null' % xmlxsd_output
227
+ #
228
+ index_xml = []
229
+ index_xml .append (glob .glob ('%s/index.xml' % (xmlxsd_output )))
230
+ index_xml .append (glob .glob ('%s/*/*/index.xml' % (xmlxsd_output )))
231
+ index_xml = ' ' .join (list (itertools .chain .from_iterable (index_xml ))).replace (self .args .outputdir + '/' ,'' ).replace ('\\ ' ,'/' )
232
+ index_xsd = []
233
+ index_xsd .append (glob .glob ('%s/index.xsd' % (xmlxsd_output )))
234
+ index_xsd .append (glob .glob ('%s/*/*/index.xsd' % (xmlxsd_output )))
235
+ index_xsd = ' ' .join (list (itertools .chain .from_iterable (index_xsd ))).replace (self .args .outputdir + '/' ,'' ).replace ('\\ ' ,'/' )
236
+ exe_string = '%s --noout --schema %s %s %s' % (self .args .xmllint ,index_xsd ,index_xml ,redirx )
237
+ exe_string += ' %s more "%s/temp"' % (separ ,xmlxsd_output )
238
+
239
+ xmllint_out = os .popen (exe_string ).read ()
240
+ if xmllint_out :
241
+ xmllint_out = re .sub (r'.*validates' ,'' ,xmllint_out ).rstrip ('\n ' )
242
+ else :
243
+ msg += ('Failed to run %s with schema %s for files: %s' % (self .args .xmllint ,index_xsd ,index_xml ),)
244
+ failed_xmlxsd = True
245
+ if xmllint_out :
246
+ msg += (xmllint_out ,)
247
+ failed_xmlxsd = True
248
+ #
249
+ compound_xml = []
250
+ compound_xml .append (glob .glob ('%s/*.xml' % (xmlxsd_output )))
251
+ compound_xml .append (glob .glob ('%s/*/*/*.xml' % (xmlxsd_output )))
252
+ compound_xml = ' ' .join (list (itertools .chain .from_iterable (compound_xml ))).replace (self .args .outputdir + '/' ,'' ).replace ('\\ ' ,'/' )
253
+ compound_xml = re .sub (r' [^ ]*/index.xml' ,'' ,compound_xml )
254
+ compound_xml = re .sub (r'[^ ]*/index.xml ' ,'' ,compound_xml )
255
+
256
+ compound_xsd = []
257
+ compound_xsd .append (glob .glob ('%s/compound.xsd' % (xmlxsd_output )))
258
+ compound_xsd .append (glob .glob ('%s/*/*/compound.xsd' % (xmlxsd_output )))
259
+ compound_xsd = ' ' .join (list (itertools .chain .from_iterable (compound_xsd ))).replace (self .args .outputdir + '/' ,'' ).replace ('\\ ' ,'/' )
260
+ exe_string = '%s --noout --schema %s %s %s' % (self .args .xmllint ,compound_xsd ,compound_xml ,redirx )
261
+ exe_string += ' %s more "%s/temp"' % (separ ,xmlxsd_output )
262
+
263
+ xmllint_out = os .popen (exe_string ).read ()
264
+ if xmllint_out :
265
+ xmllint_out = re .sub (r'.*validates' ,'' ,xmllint_out ).rstrip ('\n ' )
266
+ else :
267
+ msg += ('Failed to run %s with schema %s for files: %s' % (self .args .xmllint ,compound_xsd ,compound_xml ),)
268
+ failed_xmlxsd = True
269
+ if xmllint_out :
270
+ msg += (xmllint_out ,)
271
+ failed_xmlxsd = True
272
+
273
+ if not failed_xml and not failed_xmlxsd and not self .args .keep :
274
+ xml_output = '%s/out' % self .test_out
275
+ shutil .rmtree (xml_output ,ignore_errors = True )
221
276
222
277
if (self .args .rtf ):
223
278
# no tests defined yet
@@ -282,7 +337,7 @@ def perform_test(self,testmgr):
282
337
elif not self .args .keep :
283
338
shutil .rmtree (latex_output ,ignore_errors = True )
284
339
285
- if failed_xml or failed_html or failed_latex or failed_docbook or failed_rtf :
340
+ if failed_xml or failed_html or failed_latex or failed_docbook or failed_rtf or failed_xmlxsd :
286
341
testmgr .ok (False ,self .test_name ,msg )
287
342
return
288
343
@@ -374,6 +429,8 @@ def main():
374
429
'create docbook output and check with xmllint' ,action = "store_true" )
375
430
parser .add_argument ('--xhtml' ,help =
376
431
'create xhtml output and check with xmllint' ,action = "store_true" )
432
+ parser .add_argument ('--xmlxsd' ,help =
433
+ 'create xml output and check with xmllint against xsd' ,action = "store_true" )
377
434
parser .add_argument ('--pdf' ,help = 'create LaTeX output and create pdf from it' ,
378
435
action = "store_true" )
379
436
parser .add_argument ('--subdirs' ,help = 'use the configuration parameter CREATE_SUBDIRS=YES' ,
@@ -387,7 +444,7 @@ def main():
387
444
args = parser .parse_args (test_flags + sys .argv [1 :])
388
445
389
446
# sanity check
390
- if (not args .xml ) and (not args .pdf ) and (not args .xhtml ) and (not args .docbook and (not args .rtf )):
447
+ if (not args .xml ) and (not args .pdf ) and (not args .xhtml ) and (not args .docbook and (not args .rtf ) and ( not args . xmlxsd ) ):
391
448
args .xml = True
392
449
if (not args .updateref is None ) and (args .ids is None ) and (args .all is None ):
393
450
parser .error ('--updateref requires either --id or --all' )
0 commit comments