Exemple #1
0
    def test_root_elements(self):
        override = Override()
        redefine = Redefine()

        redefine.annotation = Annotation()
        redefine.complex_types.append(ComplexType())

        override.annotation = Annotation()
        override.groups.append(Group())
        override.simple_types.append(SimpleType())

        schema = Schema()
        schema.simple_types.append(SimpleType())
        schema.attribute_groups.append(AttributeGroup())
        schema.groups.append(Group())
        schema.attributes.append(Attribute())
        schema.complex_types.append(ComplexType())
        schema.elements.append(Element())
        schema.redefines.append(redefine)
        schema.overrides.append(override)

        iterator = SchemaMapper.root_elements(schema)
        expected = [
            ("Override", override.simple_types[0]),
            ("Override", override.groups[0]),
            ("Redefine", redefine.complex_types[0]),
            ("Schema", schema.simple_types[0]),
            ("Schema", schema.complex_types[0]),
            ("Schema", schema.groups[0]),
            ("Schema", schema.attribute_groups[0]),
            ("Schema", schema.elements[0]),
            ("Schema", schema.attributes[0]),
        ]
        self.assertEqual(expected, list(iterator))
Exemple #2
0
    def test_end_complex_type(self):
        complex_type = ComplexType()
        not_complex_type = Element()
        element = etree.Element("uno")

        self.parser.end_complex_type(not_complex_type, element)
        self.parser.end_complex_type(complex_type, element)

        self.assertEqual(0, len(complex_type.attribute_groups))
        self.assertIsNone(complex_type.open_content)

        self.parser.default_attributes = "tns:attrs"
        self.parser.end_complex_type(complex_type, element)

        expected = AttributeGroup(ref="tns:attrs")
        self.assertEqual([expected], complex_type.attribute_groups)
        self.assertIsNone(complex_type.open_content)

        default_open_content = DefaultOpenContent()
        self.parser.default_attributes = None
        self.parser.default_open_content = default_open_content
        self.parser.end_complex_type(complex_type, element)
        self.assertIs(default_open_content, complex_type.open_content)

        open_content = OpenContent()
        complex_type.open_content = open_content
        self.parser.end_complex_type(complex_type, element)
        self.assertIs(open_content, complex_type.open_content)
Exemple #3
0
    def test_build(self, mock_build_class):
        schema = self.schema
        override = Override()
        redefine = Redefine()

        redefine.annotation = Annotation()
        redefine.complex_types.append(ComplexType())

        override.annotation = Annotation()
        override.groups.append(Group())
        override.simple_types.append(SimpleType())

        schema.simple_types.append(SimpleType())
        schema.attribute_groups.append(AttributeGroup())
        schema.groups.append(Group())
        schema.attributes.append(Attribute())
        schema.complex_types.append(ComplexType())
        schema.elements.append(Element())
        schema.redefines.append(redefine)
        schema.overrides.append(override)

        self.builder.build()

        mock_build_class.assert_has_calls(
            [
                mock.call(override.simple_types[0], container=override.class_name),
                mock.call(override.groups[0], container=override.class_name),
                mock.call(redefine.complex_types[0], container=redefine.class_name),
                mock.call(schema.simple_types[0], container=schema.class_name),
                mock.call(schema.complex_types[0], container=schema.class_name),
                mock.call(schema.groups[0], container=schema.class_name),
                mock.call(schema.attribute_groups[0], container=schema.class_name),
                mock.call(schema.elements[0], container=schema.class_name),
                mock.call(schema.attributes[0], container=schema.class_name),
            ]
        )
Exemple #4
0
 def test_property_is_attribute(self):
     obj = AttributeGroup()
     self.assertTrue(obj.is_attribute)
Exemple #5
0
    def test_property_attr_types(self):
        obj = AttributeGroup()
        self.assertEqual([], list(obj.attr_types))

        obj.ref = "foo"
        self.assertEqual(["foo"], list(obj.attr_types))
    def test_property_real_type(self):
        obj = AttributeGroup()
        self.assertEqual("", obj.real_type)

        obj.ref = "foo"
        self.assertEqual("foo", obj.real_type)