Skip to content
Snippets Groups Projects
Commit 43d4dd66 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

WIP: Fix missing name argumentin JSONFileConverter.create_children

parent 91c1d829
No related branches found
No related tags found
No related merge requests found
Pipeline #31388 passed
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment