print("\n%s: %r errors, %r expected." % (self.id()[13:], num_errors, expected_errors)) if num_errors == 0: raise ValueError("found no errors when %d expected." % expected_errors) else: raise ValueError("n.%d errors expected, found %d: %s" % (expected_errors, num_errors, '\n++++++\n'.join([str(e) for e in errors]))) else: self.assertTrue( True, "Successfully created schema for {}".format(xsd_file)) rel_path = os.path.relpath(test_file) class_name = 'TestSchema{0:03}'.format(test_num) return type( class_name, (unittest.TestCase, ), {'test_schema_{0:03}_{1}'.format(test_num, rel_path): test_schema}) if __name__ == '__main__': from xmlschema.tests import print_test_header, get_testfiles, tests_factory print_test_header() testfiles = get_testfiles(os.path.dirname(os.path.abspath(__file__))) schema_tests = tests_factory(make_schema_test_class, testfiles, suffix='xsd') globals().update(schema_tests) unittest.main()
def test_dict_granularity(self): """Based on Issue #22, test to make sure an xsd indicating list with dictionaries, returns just that even when it has a single dict. """ xsd_string = os.path.join(self.test_dir, 'examples/issues/issue_022/xsd_string.xsd') xml_string_1 = os.path.join( self.test_dir, 'examples/issues/issue_022/xml_string_1.xml') xml_string_2 = os.path.join( self.test_dir, 'examples/issues/issue_022/xml_string_2.xml') xsd_schema = xmlschema.XMLSchema(xsd_string) xml_data_1 = xsd_schema.to_dict(xml_string_1) xml_data_2 = xsd_schema.to_dict(xml_string_2) self.assertTrue( type(xml_data_1['bar']) == type(xml_data_2['bar']), msg= "XSD with an array that return a single element from xml must still yield a list." ) if __name__ == '__main__': from xmlschema.tests import print_test_header, tests_factory print_test_header() path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '*/testfiles') decoding_tests = tests_factory(make_test_decoding_function, path, 'decoding', 'xml') globals().update(decoding_tests) unittest.main()
os.path.join(self.test_dir, 'cases/examples/vehicles/vehicles-1_error.xml')) self.assertTrue(xs.is_valid(xt1)) self.assertFalse(xs.is_valid(xt2)) self.assertTrue(xs.validate(xt1) is None) self.assertRaises(xmlschema.XMLSchemaValidationError, xs.validate, xt2) if __name__ == '__main__': from xmlschema.tests import print_test_header, tests_factory print_test_header() if '-s' not in sys.argv and '--skip-extra' not in sys.argv: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '*/testfiles') else: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cases/testfiles') try: sys.argv.remove('-s') except ValueError: sys.argv.remove('--skip-extra') # Validation test cases: those test don't run with the test_all.py script because are # a duplication of similar decoding tests. validation_tests = tests_factory(make_test_validation_function, path, 'validation', 'xml') globals().update(validation_tests) unittest.main()
SchemaObserver.clear() del self.errors[:] start_time = time.time() if expected_warnings > 0: with warnings.catch_warnings(record=True) as ctx: warnings.simplefilter("always") self.check_schema() self.assertEqual(len(ctx), expected_warnings, "Wrong number of include/import warnings") else: self.check_schema() # Check with lxml.etree.XMLSchema class if check_with_lxml and lxml_etree is not None: self.check_lxml_schema(xmlschema_time=time.time()-start_time) self.check_errors(xsd_file, expected_errors) TestSchema.__name__ = TestSchema.__qualname__ = str('TestSchema{0:03}'.format(test_num)) return TestSchema # Creates schema tests from XSD files globals().update(tests_factory(make_schema_test_class, 'xsd')) if __name__ == '__main__': from xmlschema.tests import print_test_header print_test_header() unittest.main()
import os import sys try: import xmlschema except ImportError: # Adds the package base dir path as first search path for imports pkg_base_dir = os.path.dirname( os.path.dirname(os.path.dirname(__file__))) sys.path.insert(0, pkg_base_dir) import xmlschema from xmlschema.tests import tests_factory, print_test_header, get_testfiles from xmlschema.tests.test_regex import TestCodePoints, TestUnicodeSubset, TestUnicodeCategories from xmlschema.tests.test_xpath import XsdXPathTest from xmlschema.tests.test_resources import TestResources from xmlschema.tests.test_meta import TestBuiltinTypes, TestGlobalMaps from xmlschema.tests.test_schemas import make_schema_test_class, TestXMLSchema10 from xmlschema.tests.test_validators import (make_validator_test_class, TestValidation, TestDecoding, TestEncoding) from xmlschema.tests.test_package import TestPackage print_test_header() testfiles = get_testfiles(os.path.dirname(os.path.abspath(__file__))) globals().update(tests_factory(make_schema_test_class, testfiles, 'xsd')) globals().update(tests_factory(make_validator_test_class, testfiles, 'xml')) unittest.main()
start_time = time.time() if expected_warnings > 0: with warnings.catch_warnings(record=True) as ctx: warnings.simplefilter("always") self.check_schema() self.assertEqual( len(ctx), expected_warnings, "%r: Wrong number of include/import warnings" % xsd_file) else: self.check_schema() # Check with lxml.etree.XMLSchema class if check_with_lxml and lxml_etree is not None: self.check_lxml_schema(xmlschema_time=time.time() - start_time) self.check_errors(xsd_file, expected_errors) TestSchema.__name__ = TestSchema.__qualname__ = str( 'TestSchema{0:03}'.format(test_num)) return TestSchema # Creates schema tests from XSD files globals().update(tests_factory(make_schema_test_class, 'xsd')) if __name__ == '__main__': from xmlschema.tests import print_test_header print_test_header() unittest.main()
import xmlschema except ImportError: # Adds the package base dir path as first search path for imports pkg_base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) sys.path.insert(0, pkg_base_dir) import xmlschema from xmlschema.tests import tests_factory, print_test_header from xmlschema.tests.test_regex import TestCodePoints, TestUnicodeSubset, TestUnicodeCategories from xmlschema.tests.test_xpath import XsdXPathTest from xmlschema.tests.test_resources import TestResources from xmlschema.tests.test_meta import TestBuiltinTypes, TestGlobalMaps from xmlschema.tests.test_schemas import make_test_schema_function from xmlschema.tests.test_decoding import make_test_decoding_function, TestDecoding from xmlschema.tests.test_validation import TestValidation print_test_header() if '-s' not in sys.argv and '--skip-extra' not in sys.argv: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '*/testfiles') else: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cases/testfiles') try: sys.argv.remove('-s') except ValueError: sys.argv.remove('--skip-extra') globals().update(tests_factory(make_test_schema_function, path, 'schema', 'xsd')) globals().update(tests_factory(make_test_decoding_function, path, 'decoding', 'xml')) unittest.main()
<sequence> <element name="B1" type="string"/> <element name="B2" type="integer"/> <element name="B3" type="boolean"/> </sequence> </complexType> """) self.check_encode( xsd_component=schema.elements['A'], data=ordered_dict_class([('B1', 'abc'), ('B2', 10), ('B3', False)]), expected=u'<ns:A xmlns:ns="ns">\n<B1>abc</B1>\n<B2>10</B2>\n<B3>false</B3>\n </ns:A>', indent=0, ) self.check_encode(schema.elements['A'], {'B1': 'abc', 'B2': 10, 'B4': False}, XMLSchemaValidationError) self.check_encode( xsd_component=schema.elements['A'], data=ordered_dict_class([('B1', 'abc'), ('B2', 10), ('#1', 'hello')]), expected=u'<ns:A xmlns:ns="ns">\n<B1>abc</B1>\n<B2>10</B2>hello\n </ns:A>', indent=0, cdata_prefix='#' ) if __name__ == '__main__': from xmlschema.tests import print_test_header, tests_factory, get_testfiles print_test_header() testfiles = get_testfiles(os.path.dirname(os.path.abspath(__file__))) decoder_tests = tests_factory(make_validator_test_class, testfiles, 'xml') globals().update(decoder_tests) unittest.main()
(expected_errors, num_errors, errors[0])) else: self.assertTrue( True, "Successfully created schema for {}".format(xsd_file)) return test_schema if __name__ == '__main__': from xmlschema.tests import print_test_header, tests_factory print_test_header() if '-s' not in sys.argv and '--skip-extra' not in sys.argv: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '*/testfiles') else: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cases/testfiles') try: sys.argv.remove('-s') except ValueError: sys.argv.remove('--skip-extra') schema_tests = tests_factory(make_test_schema_function, path, label='schema', suffix='xsd') globals().update(schema_tests) unittest.main()
try: import xmlschema except ImportError: # Adds the package base dir path as first search path for imports pkg_base_dir = os.path.dirname( os.path.dirname(os.path.dirname(__file__))) sys.path.insert(0, pkg_base_dir) import xmlschema from xmlschema.tests import tests_factory, print_test_header from xmlschema.tests.test_regex import TestCodePoints, TestUnicodeSubset, TestUnicodeCategories from xmlschema.tests.test_xpath import TestXPath from xmlschema.tests.test_resources import TestResources from xmlschema.tests.test_meta import TestBuiltinTypes, TestGlobalMaps from xmlschema.tests.test_schemas import make_test_schema_function from xmlschema.tests.test_decoding import make_test_decoding_function, TestDecoding from xmlschema.tests.test_validation import make_test_validation_function, TestValidation print_test_header() path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '*/testfiles') globals().update( tests_factory(make_test_schema_function, path, 'schema', 'xsd')) globals().update( tests_factory(make_test_validation_function, path, 'validation', 'xml')) globals().update( tests_factory(make_test_decoding_function, path, 'decoding', 'xml')) unittest.main()