From bc112cf6f2ac96950b3a0c3b98c23c938c694de7 Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Tue, 19 Nov 2024 15:18:08 +0100 Subject: [PATCH] FIX: Don't ignore top-level description or unit if datatype is given --- src/caosadvancedtools/models/parser.py | 33 +++++++++++--------------- unittests/test_yaml_model_parser.py | 25 +++++++++++++++++-- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index fb8f75ab..b1e3aa95 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -351,25 +351,20 @@ debug : bool, optional if prop.name in self.model: model_prop = self.model[prop.name] # The information must be missing, we don't want to overwrite it accidentally: - if prop.datatype is not None and prop.datatype != model_prop.datatype: - continue - # TODO: Data type overwrite is allowed here (because - # of lists), but this might change in the future. - # raise RuntimeError("datatype must not be set, here. This is probably a bug.") - if prop.unit is not None and prop.unit != model_prop.unit: - continue - if prop.description is not None and prop.description != model_prop.description: - continue - - # If this property has a more detailed definition in the model, - # copy over the information: - - if isinstance(model_prop, db.RecordType): - # in this case the datatype equals the name of the record type: - prop.datatype = prop.name - else: - prop.datatype = model_prop.datatype - prop.unit = model_prop.unit + if prop.datatype is None: + if isinstance(model_prop, db.RecordType): + prop.datatype = model_prop.name + else: + prop.datatype = model_prop.datatype + # TODO: Data type overwrite is allowed here (because + # of lists), but this might change in the future. + # elif prop.datatype != model_prop.datatype: + # raise RuntimeError("datatype must not be set, here. This is probably a bug.") + if prop.unit is None: + # No unit for plain reference properties + if not isinstance(model_prop, db.RecordType): + prop.unit = model_prop.unit + if prop.description is None: prop.description = model_prop.description return DataModel(self.model.values()) diff --git a/unittests/test_yaml_model_parser.py b/unittests/test_yaml_model_parser.py index cf999789..8728e128 100644 --- a/unittests/test_yaml_model_parser.py +++ b/unittests/test_yaml_model_parser.py @@ -657,9 +657,11 @@ RT1: obligatory_properties: foo: RT2: + datatype: LIST<RT2> test_reference: RT2: + description: Describe RT2 test_reference: datatype: RT2 @@ -681,10 +683,10 @@ test_reference: <RecordType id="2273" name="RT1"> <Version id="0c1b9df6677ee40d1e1429b2123e078ee6c863e0" head="true"/> <Property id="2272" name="foo" description="bla bla" datatype="INTEGER" unit="m" importance="OBLIGATORY" flag="inheritance:FIX"/> - <Property id="2274" name="RT2" datatype="RT2" importance="OBLIGATORY" flag="inheritance:FIX"/> + <Property id="2274" name="RT2" description="Describe RT2" datatype="LIST<RT2>" importance="OBLIGATORY" flag="inheritance:FIX"/> <Property id="2275" name="test_reference" datatype="RT2" importance="OBLIGATORY" flag="inheritance:FIX"/> </RecordType> - <RecordType id="2274" name="RT2"> + <RecordType id="2274" name="RT2" description="Describe RT2"> <Version id="185940642680a7eba7f71914dd8dd7758dd13faa" head="true"/> </RecordType> <Property id="2275" name="test_reference" datatype="RT2"> @@ -699,13 +701,32 @@ test_reference: c3 = compare_entities(model["RT2"], entities[2]) c4 = compare_entities(model["test_reference"], entities[3]) + # Make sure the mock response matches the datamodel definiton + # exactly, i.e., they only differ in ids which are None for all + # entities from the datamodel and not None for the mocked + # response. for cs in (c1, c2, c3, c4): assert "id" in cs[0] assert cs[0]["id"] is None + assert cs[0]["parents"] == [] + for name, val in cs[0]["properties"].items(): + # Also properties differ in ids: The one from the + # datamodel have None + assert len(val) == 1 + assert "id" in val + assert val["id"] is None assert "id" in cs[1] assert cs[1]["id"] is not None + assert cs[1]["parents"] == [] + for name, val in cs[1]["properties"].items(): + # Also properties differ in ids: The one from the + # mock response have not None + assert len(val) == 1 + assert "id" in val + assert val["id"] is not None # The server response would be the same as the xml above: + def get_existing_entities(ent_cont): return entities -- GitLab