1#!/usr/bin/env python 2# 3# Copyright (c), 2016-2020, SISSA (International School for Advanced Studies). 4# All rights reserved. 5# This file is distributed under the terms of the MIT License. 6# See the file 'LICENSE' in the root directory of the present 7# distribution, or http://opensource.org/licenses/MIT. 8# 9# @author Davide Brunato <brunato@sissa.it> 10# 11"""Tests concerning the validation/decoding/encoding of XML files""" 12 13import os 14 15from xmlschema.testing import get_test_program_args_parser, \ 16 factory_tests, make_validation_test_class 17 18DEFAULT_TESTFILES = os.path.join(os.path.dirname(__file__), 'test_cases/testfiles') 19 20 21if __name__ == '__main__': 22 import unittest 23 import platform 24 25 args = get_test_program_args_parser(DEFAULT_TESTFILES).parse_args() 26 27 validation_tests = factory_tests( 28 test_class_builder=make_validation_test_class, 29 testfiles=args.testfiles, 30 suffix='xml', 31 check_with_lxml=args.lxml, 32 codegen=args.codegen, 33 verbosity=args.verbosity, 34 ) 35 globals().update(validation_tests) 36 37 argv = [__file__] 38 if args.tb_locals: 39 argv.append('--local') 40 for pattern in args.patterns: 41 argv.append('-k') 42 argv.append(pattern) 43 44 header_template = "XML validation tests for xmlschema with Python {} on {}" 45 header = header_template.format(platform.python_version(), platform.platform()) 46 print('{0}\n{1}\n{0}'.format("*" * len(header), header)) 47 48 unittest.main(argv=argv, verbosity=args.verbosity, failfast=args.failfast, 49 catchbreak=args.catchbreak, buffer=args.buffer) 50else: 51 # Creates schema tests from XSD files 52 globals().update(factory_tests( 53 test_class_builder=make_validation_test_class, 54 suffix='xml', 55 testfiles=DEFAULT_TESTFILES 56 )) 57