def test_end_extension(self): extension = Extension() not_extension = Element() element = etree.Element("uno") self.parser.end_extension(not_extension, element) self.parser.end_extension(extension, element) default_open_content = DefaultOpenContent() self.parser.default_open_content = default_open_content self.parser.end_extension(extension, element) self.assertIs(default_open_content, extension.open_content) open_content = OpenContent() extension.open_content = open_content self.parser.end_extension(extension, element) self.assertIs(open_content, extension.open_content)
def test_end_extension(self): extension = Extension() not_extension = Element() self.parser.end_extension(not_extension) self.parser.end_extension(extension) default_open_content = DefaultOpenContent() self.parser.default_open_content = default_open_content self.parser.end_extension(extension) self.assertIs(default_open_content, extension.open_content) open_content = OpenContent() extension.open_content = open_content self.parser.end_extension(extension) self.assertIs(open_content, extension.open_content) obj = ComplexType() self.parser.end_extension(obj) self.assertIsNone(obj.open_content)
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_property_bases(self): obj = Extension() self.assertEqual([], list(obj.bases)) obj.base = "a b c" self.assertEqual(["a b c"], list(obj.bases))
def test_property_extensions(self): obj = Extension() self.assertIsInstance(obj.extensions, Iterator) self.assertEqual([], list(obj.extensions)) obj.base = "a b c" self.assertEqual(["a b c"], list(obj.extensions))