def test_element_children(self): sequence_one = Sequence(elements=[Element(), Element()]) sequence_two = Sequence(max_occurs=2, elements=[Element(), Element()]) restriction = Restriction( enumerations=[Enumeration(value=x) for x in "abc"], sequence=sequence_two, ) complex_type = ComplexType( attributes=[Attribute(), Attribute()], sequence=sequence_one, simple_content=SimpleContent(restriction=Restriction()), complex_content=ComplexContent(restriction=restriction,), ) restrictions = Restrictions.from_element(complex_type) children = self.builder.element_children(complex_type, restrictions) expected = [ (sequence_two.elements[0], Restrictions.from_element(sequence_two)), (sequence_two.elements[1], Restrictions.from_element(sequence_two)), (restriction.enumerations[0], Restrictions.from_element(restriction)), (restriction.enumerations[1], Restrictions.from_element(restriction)), (restriction.enumerations[2], Restrictions.from_element(restriction)), (sequence_one.elements[0], Restrictions.from_element(sequence_one)), (sequence_one.elements[1], Restrictions.from_element(sequence_one)), (complex_type.attributes[0], Restrictions.from_element(complex_type)), (complex_type.attributes[1], Restrictions.from_element(complex_type)), ] self.assertIsInstance(children, GeneratorType) self.assertEqual(expected, list(children))
def test_property_is_mixed(self): obj = ComplexType() self.assertFalse(obj.is_mixed) obj.complex_content = ComplexContent() self.assertFalse(obj.is_mixed) obj.complex_content.mixed = True self.assertTrue(obj.is_mixed) obj.complex_content.mixed = False obj.mixed = True self.assertTrue(obj.is_mixed)
def test_children_extensions(self): complex_type = ComplexType( attributes=[Attribute(index=i) for i in range(2)], simple_content=SimpleContent(restriction=Restriction(base="bk:b", index=4)), complex_content=ComplexContent(extension=Extension(base="bk:ext", index=7)), ) item = ClassFactory.create() children = self.builder.children_extensions(complex_type, item) expected = list( map( ExtensionFactory.create, [ AttrTypeFactory.create(name="bk:b", index=4), AttrTypeFactory.create(name="bk:ext", index=7), ], ) ) self.assertIsInstance(children, GeneratorType) self.assertEqual(expected, list(children))
def test_children_extensions(self): complex_type = ComplexType( attributes=[Attribute() for _ in range(2)], simple_content=SimpleContent(restriction=Restriction(base="bk:b")), complex_content=ComplexContent(extension=Extension(base="bk:c")), ) complex_type.simple_content.restriction.index = 4 complex_type.complex_content.extension.index = 7 item = ClassFactory.create(ns_map={"bk": "book"}) children = SchemaMapper.children_extensions(complex_type, item) expected = list( map( ExtensionFactory.create, [ AttrTypeFactory.create(qname=build_qname("book", "b")), AttrTypeFactory.create(qname=build_qname("book", "c")), ], )) self.assertIsInstance(children, GeneratorType) self.assertEqual(expected, list(children))
def test_end_complex_type(self): complex_type = ComplexType() not_complex_type = Element() self.parser.end_complex_type(not_complex_type) self.parser.end_complex_type(complex_type) 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) 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) 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) self.assertIs(open_content, complex_type.open_content) complex_type = ComplexType() complex_type.complex_content = ComplexContent() self.parser.end_complex_type(complex_type) self.assertIsNone(complex_type.open_content) obj = Extension() self.parser.end_complex_type(obj) self.assertIsNone(obj.open_content)
def test_class(self): obj = ComplexContent() self.assertIsInstance(obj, SimpleContent) self.assertFalse(obj.mixed)