57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright (c), 2016-2019, SISSA (International School for Advanced Studies).
|
|
# All rights reserved.
|
|
# This file is distributed under the terms of the MIT License.
|
|
# See the file 'LICENSE' in the root directory of the present
|
|
# distribution, or http://opensource.org/licenses/MIT.
|
|
#
|
|
# @author Davide Brunato <brunato@sissa.it>
|
|
#
|
|
from __future__ import print_function, unicode_literals
|
|
import unittest
|
|
|
|
from xmlschema import XMLSchemaParseError
|
|
from xmlschema.tests import XsdValidatorTestCase
|
|
from xmlschema.validators import XMLSchema11
|
|
|
|
|
|
class TestXsdAttributes(XsdValidatorTestCase):
|
|
|
|
def test_wrong_attribute(self):
|
|
self.check_schema("""
|
|
<xs:attributeGroup name="alpha">
|
|
<xs:attribute name="name" type="xs:string"/>
|
|
<xs:attribute ref="phone"/> <!-- Missing "phone" attribute -->
|
|
</xs:attributeGroup>
|
|
""", XMLSchemaParseError)
|
|
|
|
def test_wrong_attribute_group(self):
|
|
self.check_schema("""
|
|
<xs:attributeGroup name="alpha">
|
|
<xs:attribute name="name" type="xs:string"/>
|
|
<xs:attributeGroup ref="beta"/> <!-- Missing "beta" attribute group -->
|
|
</xs:attributeGroup>
|
|
""", XMLSchemaParseError)
|
|
|
|
schema = self.check_schema("""
|
|
<xs:attributeGroup name="alpha">
|
|
<xs:attribute name="name" type="xs:string"/>
|
|
<xs:attributeGroup name="beta"/> <!-- attribute "name" instead of "ref" -->
|
|
</xs:attributeGroup>
|
|
""", validation='lax')
|
|
self.assertTrue(isinstance(schema.all_errors[1], XMLSchemaParseError))
|
|
|
|
|
|
class TestXsd11Attributes(TestXsdAttributes):
|
|
|
|
schema_class = XMLSchema11
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from xmlschema.tests import print_test_header
|
|
|
|
print_test_header()
|
|
unittest.main()
|