Example #1
0
    def get(self, name):
        from_namespace = self._get_from_namespace(name)
        if from_namespace:
            return from_namespace

        if name not in self.types:
            return None

        el, parsed = self.types[name]

        if not parsed:
            # Create an "empty" element to avoid circular dependency
            # If it exists in self.types, we'll return it in the subsequent
            # calls of 'element_parser', after we needs to fill this element with
            # proper data
            ref = ElementType(name)
            self.types[name][1] = ref

            parse_result = self.element_parser(el)
            if parse_result:
                _, parse_element = parse_result
                ref.fill_with(parse_element)

            parsed = ref

        return parsed
Example #2
0
def test_element_fill_with_must_copy_all_data_from_other_element():
    element_type = ElementType('xsd:string')

    name_elem = Element(name='Name', element_type=element_type)
    surname_elem = Element(name='Surname', element_type=element_type)

    f = ElementType(name='ModelType', children=[name_elem, surname_elem])
    f.annotation = 'A simple documentation for type'

    f2 = ElementType('')

    f2.fill_with(f)

    assert f2.name == f.name
    assert f2.children == f.children

    assert f2.annotation == 'A simple documentation for type'
    assert f2.children_original_order == f.children_original_order