def process_json_documents(self, uris: List[str]): """Process a list of json resources.""" classes = [] for uri in uris: input_stream = self.load_resource(uri) if input_stream: data = json.load(io.BytesIO(input_stream)) logger.info("Parsing document %s", os.path.basename(uri)) name = self.config.output.package.split(".")[-1] classes.extend(DictMapper.map(data, name)) dirname = os.path.dirname(uris[0]) if uris else "" self.class_map[dirname] = ClassUtils.reduce(classes)
def process_xml_documents(self, uris: List[str]): """Process a list of xml resources.""" classes = [] parser = TreeParser() for uri in uris: input_stream = self.load_resource(uri) if input_stream: logger.info("Parsing document %s", os.path.basename(uri)) any_element: AnyElement = parser.from_bytes(input_stream) classes.extend(ElementMapper.map(any_element)) dirname = os.path.dirname(uris[0]) if uris else "" self.class_map[dirname] = ClassUtils.reduce(classes)
def test_reduce(self, mock_merge_attributes): first = ClassFactory.elements(2) second = first.clone() second.attrs.append(AttrFactory.create()) third = second.clone() third.attrs.append(AttrFactory.create()) fourth = ClassFactory.create() actual = ClassUtils.reduce([first, second, third, fourth]) self.assertEqual([third, fourth], list(actual)) mock_merge_attributes.assert_has_calls( [ mock.call(third, first), mock.call(third, second), ] )