Skip to content
Snippets Groups Projects
Verified Commit d757f2b7 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

STY: Some style changes.

parent 9cc0ae43
No related branches found
No related tags found
2 merge requests!39Release 0.4.0,!33F json schema datamodel
# -*- mode:conf; -*-
[FORMAT]
# Good variable names which should always be accepted, separated by a comma
good-names=ii,rt
[TYPECHECK]
ignored-modules=etree
[pytest] [pytest]
testpaths = unittests testpaths = unittests
addopts = -vv addopts = -vv
python_paths = src
...@@ -99,6 +99,7 @@ class YamlDefinitionError(RuntimeError): ...@@ -99,6 +99,7 @@ class YamlDefinitionError(RuntimeError):
class JsonSchemaDefinitionError(RuntimeError): class JsonSchemaDefinitionError(RuntimeError):
# @author Florian Spreckelsen # @author Florian Spreckelsen
# @date 2022-02-17 # @date 2022-02-17
# @review Daniel Hornung 2022-02-18
def __init__(self, msg): def __init__(self, msg):
super().__init__(msg) super().__init__(msg)
...@@ -121,6 +122,7 @@ def parse_model_from_json_schema(filename: str): ...@@ -121,6 +122,7 @@ def parse_model_from_json_schema(filename: str):
"""Return a datamodel parsed from a json schema definition.""" """Return a datamodel parsed from a json schema definition."""
# @author Florian Spreckelsen # @author Florian Spreckelsen
# @date 2022-02-17 # @date 2022-02-17
# @review Daniel Hornung 2022-02-18
parser = JsonSchemaParser() parser = JsonSchemaParser()
return parser.parse_model_from_json_schema(filename) return parser.parse_model_from_json_schema(filename)
...@@ -466,6 +468,7 @@ class JsonSchemaParser(Parser): ...@@ -466,6 +468,7 @@ class JsonSchemaParser(Parser):
"""Extends the yaml parser to read in datamodels defined in a json schema.""" """Extends the yaml parser to read in datamodels defined in a json schema."""
# @author Florian Spreckelsen # @author Florian Spreckelsen
# @date 2022-02-17 # @date 2022-02-17
# @review Daniel Hornung 2022-02-18
def parse_model_from_json_schema(self, filename: str): def parse_model_from_json_schema(self, filename: str):
"""Return a datamodel created from the definition in the json schema in """Return a datamodel created from the definition in the json schema in
...@@ -506,12 +509,10 @@ class JsonSchemaParser(Parser): ...@@ -506,12 +509,10 @@ class JsonSchemaParser(Parser):
model_dict = [model_dict] model_dict = [model_dict]
for ii, elt in enumerate(model_dict): for ii, elt in enumerate(model_dict):
if not "title" in elt: if "title" not in elt:
raise JsonSchemaDefinitionError( raise JsonSchemaDefinitionError(f"Object {ii+1} is lacking the `title` key word")
"Object {} is lacking the `title` key word".format(ii+1)) if "type" not in elt:
if not "type" in elt: raise JsonSchemaDefinitionError(f"Object {ii+1} is lacking the `type` key word")
raise JsonSchemaDefinitionError(
"Object {} is lacking the `type` key word".format(ii+1))
name = self._stringify(elt["title"], context=elt) name = self._stringify(elt["title"], context=elt)
self._treat_element(elt, name) self._treat_element(elt, name)
...@@ -535,8 +536,7 @@ class JsonSchemaParser(Parser): ...@@ -535,8 +536,7 @@ class JsonSchemaParser(Parser):
elif elt["type"] == "object": elif elt["type"] == "object":
ent = self._treat_record_type(elt, name) ent = self._treat_record_type(elt, name)
else: else:
raise NotImplementedError( raise NotImplementedError(f"Cannot parse items of type '{elt['type']}' (yet).")
"Cannot parse items of type '{}' (yet).".format(elt["type"]))
if "description" in elt: if "description" in elt:
ent.description = elt["description"] ent.description = elt["description"]
...@@ -552,7 +552,7 @@ class JsonSchemaParser(Parser): ...@@ -552,7 +552,7 @@ class JsonSchemaParser(Parser):
if "properties" in elt: if "properties" in elt:
for key, prop in elt["properties"].items(): for key, prop in elt["properties"].items():
if "title" in prop: if "title" in prop:
name = self._stringify(title) name = self._stringify(prop["title"])
else: else:
name = self._stringify(key) name = self._stringify(key)
prop_ent = self._treat_element(prop, name) prop_ent = self._treat_element(prop, name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment