From 43d4dd66cca74b0fb68fd62af5620eb2c84301a7 Mon Sep 17 00:00:00 2001
From: fspreck <f.spreckelsen@indiscale.com>
Date: Mon, 5 Dec 2022 17:55:56 +0100
Subject: [PATCH] WIP: Fix missing name argumentin
 JSONFileConverter.create_children

---
 src/caoscrawler/converters.py | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/caoscrawler/converters.py b/src/caoscrawler/converters.py
index efdbb102..6dc96ba9 100644
--- a/src/caoscrawler/converters.py
+++ b/src/caoscrawler/converters.py
@@ -546,7 +546,8 @@ def convert_basic_element(element: Union[list, dict, bool, int, float, str, None
         return NoneElement(name)
     else:
         raise NotImplementedError(
-            msg_prefix + f"The object that has an unexpected type: {type(element)}\n"
+            msg_prefix +
+            f"The object that has an unexpected type: {type(element)}\n"
             f"The object is:\n{str(element)}")
 
 
@@ -579,7 +580,8 @@ class DictElementConverter(Converter):
     def create_children(self, generalStore: GeneralStore, element: StructureElement):
         # TODO: See comment on types and inheritance
         if not isinstance(element, DictElement):
-            raise ValueError("create_children was called with wrong type of StructureElement")
+            raise ValueError(
+                "create_children was called with wrong type of StructureElement")
 
         return self._create_children_from_dict(element.value)
 
@@ -638,14 +640,16 @@ class JSONFileConverter(Converter):
     def create_children(self, generalStore: GeneralStore, element: StructureElement):
         # TODO: See comment on types and inheritance
         if not isinstance(element, File):
-            raise ValueError("create_children was called with wrong type of StructureElement")
+            raise ValueError(
+                "create_children was called with wrong type of StructureElement")
         with open(element.path, 'r') as json_file:
             json_data = json.load(json_file)
         if "validate" in self.definition and self.definition["validate"]:
-            validate_against_json_schema(json_data, self.definition["validate"])
+            validate_against_json_schema(
+                json_data, self.definition["validate"])
         structure_element = convert_basic_element(
-            json_data, "The JSON File contained content that was parsed to a Python object"
-            " with an unexpected type.")
+            json_data, name=element.name+"_child_dict", msg_prefix="The JSON File contained "
+            "content that was parsed to a Python object with an unexpected type.")
         return [structure_element]
 
 
@@ -665,13 +669,15 @@ class YAMLFileConverter(Converter):
     def create_children(self, generalStore: GeneralStore, element: StructureElement):
         # TODO: See comment on types and inheritance
         if not isinstance(element, File):
-            raise ValueError("create_children was called with wrong type of StructureElement")
+            raise ValueError(
+                "create_children was called with wrong type of StructureElement")
         with open(element.path, 'r') as yaml_file:
             yaml_data = yaml.safe_load(yaml_file)
         if "validate" in self.definition and self.definition["validate"]:
-            validate_against_json_schema(yaml_data, self.definition["validate"])
+            validate_against_json_schema(
+                yaml_data, self.definition["validate"])
         structure_element = convert_basic_element(
-            yaml_data, "The YAML File contained content that was parsed to a Python object"
+            yaml_data, msg_prefix="The YAML File contained content that was parsed to a Python object"
             " with an unexpected type.")
         return [structure_element]
 
@@ -689,7 +695,8 @@ def match_name_and_value(definition, name, value):
     """
     if "match_name" in definition:
         if "match" in definition:
-            raise RuntimeError(f"Do not supply both, 'match_name' and 'match'.")
+            raise RuntimeError(
+                f"Do not supply both, 'match_name' and 'match'.")
 
         m1 = re.match(definition["match_name"], name)
         if m1 is None:
@@ -760,7 +767,8 @@ class _AbstractScalarValueElementConverter(Converter):
                 and not isinstance(element, BooleanElement)
                 and not isinstance(element, IntegerElement)
                 and not isinstance(element, FloatElement)):
-            raise ValueError("create_children was called with wrong type of StructureElement")
+            raise ValueError(
+                "create_children was called with wrong type of StructureElement")
         return match_name_and_value(self.definition, element.name, element.value)
 
     def _typecheck(self, element: StructureElement, allowed_matches: dict):
-- 
GitLab