def parse(self): if self.root_list_path is None: root_json_list = self.root_json_dict else: root_json_list = path_search(self.root_json_dict, self.root_list_path.split('/')) for json_dict in root_json_list: self.parse_json_dict(json_dict, sheet=self.main_sheet)
def parse(self): if self.root_list_path is None: root_json_list = self.root_json_dict else: root_json_list = path_search(self.root_json_dict, self.root_list_path.split("/")) for json_dict in root_json_list: if json_dict is None: # This is particularly useful for IATI XML, in order to not # fallover on empty activity, e.g. <iati-activity/> continue self.parse_json_dict(json_dict, sheet=self.main_sheet) if self.remove_empty_schema_columns: # Remove sheets with no lines of data for sheet_name, sheet in list(self.sub_sheets.items()): if not sheet.lines: del self.sub_sheets[sheet_name] if self.preserve_fields_input: nonexistent_input_paths = [] for field in self.preserve_fields_input: if field not in self.seen_paths: nonexistent_input_paths.append(field) if len(nonexistent_input_paths) > 0: warn( _("You wanted to preserve the following fields which are not present in the input data: {}" ).format(nonexistent_input_paths))
def parse(self): if self.root_list_path is None: root_json_list = self.root_json_dict else: root_json_list = path_search(self.root_json_dict, self.root_list_path.split('/')) for json_dict in root_json_list: if json_dict is None: # This is particularly useful for IATI XML, in order to not # fallover on empty activity, e.g. <iati-activity/> continue self.parse_json_dict(json_dict, sheet=self.main_sheet)
def test_path_search(): goal_dict = {} assert goal_dict is not {} # following tests rely on this assert path_search(goal_dict, []) is goal_dict assert path_search({'testA': goal_dict}, ['testA']) is goal_dict assert path_search({'a1': { 'b1': { 'c1': goal_dict } }}, ['a1', 'b1', 'c1']) is goal_dict assert path_search({'a1': { 'b1': { 'c1': goal_dict } }}, ['a1', 'b1[]'], id_fields={'a1/b1[]/id': 'c1'}) is goal_dict assert path_search({'a1': { 'b1': { 'c1': goal_dict } }}, ['a1[]', 'c1'], id_fields={'a1[]/id': 'b1'}) is goal_dict # Top is always assumed to be an arary assert path_search({'a1': { 'b1': { 'c1': goal_dict } }}, ['a1', 'c1'], id_fields={'a1/id': 'b1'}, top=True) is goal_dict
def parse(self): if self.root_list_path is None: root_json_list = self.root_json_dict else: root_json_list = path_search(self.root_json_dict, self.root_list_path.split('/')) for json_dict in root_json_list: if json_dict is None: # This is particularly useful for IATI XML, in order to not # fallover on empty activity, e.g. <iati-activity/> continue self.parse_json_dict(json_dict, sheet=self.main_sheet) if self.remove_empty_schema_columns: # Remove sheets with no lines of data for sheet_name, sheet in list(self.sub_sheets.items()): if not sheet.lines: del self.sub_sheets[sheet_name]
def test_path_search(): goal_dict = {} assert goal_dict is not {} # following tests rely on this assert path_search(goal_dict, []) is goal_dict assert path_search({"testA": goal_dict}, ["testA"]) is goal_dict assert (path_search({"a1": { "b1": { "c1": goal_dict } }}, ["a1", "b1", "c1"]) is goal_dict) assert (path_search( {"a1": { "b1": { "c1": goal_dict } }}, ["a1", "b1[]"], id_fields={"a1/b1[]/id": "c1"}, ) is goal_dict) assert (path_search( {"a1": { "b1": { "c1": goal_dict } }}, ["a1[]", "c1"], id_fields={"a1[]/id": "b1"}, ) is goal_dict) # Top is always assumed to be an arary assert (path_search( {"a1": { "b1": { "c1": goal_dict } }}, ["a1", "c1"], id_fields={"a1/id": "b1"}, top=True, ) is goal_dict)
def test_path_search(): goal_dict = {} assert goal_dict is not {} # following tests rely on this assert path_search(goal_dict, []) is goal_dict assert path_search( {'testA': goal_dict}, ['testA']) is goal_dict assert path_search( {'a1': {'b1': {'c1': goal_dict}}}, ['a1', 'b1', 'c1']) is goal_dict assert path_search( {'a1': {'b1': {'c1': goal_dict}}}, ['a1', 'b1[]'], id_fields={'a1/b1[]/id': 'c1'}) is goal_dict assert path_search( {'a1': {'b1': {'c1': goal_dict}}}, ['a1[]', 'c1'], id_fields={'a1[]/id': 'b1'}) is goal_dict # Top is always assumed to be an arary assert path_search( {'a1': {'b1': {'c1': goal_dict}}}, ['a1', 'c1'], id_fields={'a1/id': 'b1'}, top=True) is goal_dict