Skip to content
Snippets Groups Projects
Commit f11a466d authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST(yaml-model-parser): incomplete test for correct output of parser in case of no changes

parent b65b8426
Branches
Tags
2 merge requests!128MNT: Added a warning when column metadata is not configured, and a better...,!115add datatype, unit and description to properties that are part of Records
Pipeline #56980 failed
...@@ -111,8 +111,11 @@ class DataModel(dict): ...@@ -111,8 +111,11 @@ class DataModel(dict):
existing_entities = db.Container().extend( existing_entities = db.Container().extend(
DataModel.entities_without( DataModel.entities_without(
self.values(), [e.name.lower() for e in non_existing_entities])) self.values(), [e.name.lower() for e in non_existing_entities]))
self.sync_ids_by_name(tmp_exist) self.sync_ids_by_name(tmp_exist)
if len(non_existing_entities) > 0: if len(non_existing_entities) > 0:
if verbose: if verbose:
print("New entities:") print("New entities:")
...@@ -174,7 +177,7 @@ class DataModel(dict): ...@@ -174,7 +177,7 @@ class DataModel(dict):
Args Args
---- ----
entities : iterable entities : iterable
The entities to be retrieved. This object will not be moidified. The entities to be retrieved. This object will not be modified.
Raises Raises
------ ------
......
...@@ -341,37 +341,38 @@ debug : bool, optional ...@@ -341,37 +341,38 @@ debug : bool, optional
f"invalid keyword in line {entity['__line__']}:", 1) f"invalid keyword in line {entity['__line__']}:", 1)
raise ValueError(err_str, *err.args[1:]) from err raise ValueError(err_str, *err.args[1:]) from err
# TODO: functionality commented out, to be able to test failing test first.
# Update properties that are part of record types: # Update properties that are part of record types:
# e.g. add their datatypes, units etc.. # e.g. add their datatypes, units etc..
# Otherwise comparison of existing models and the parsed model become difficult. # Otherwise comparison of existing models and the parsed model become difficult.
for name, ent in self.model.items(): # for name, ent in self.model.items():
if not isinstance(ent, db.RecordType): # if not isinstance(ent, db.RecordType):
continue
props = ent.get_properties()
for prop in props:
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:
# breakpoint()
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
raise RuntimeError("unit must not be set, here. This is probably a bug.")
if prop.description is not None and prop.description != model_prop.description:
# continue # continue
raise RuntimeError("description must not be set, here. This is probably a bug.") # props = ent.get_properties()
# for prop in props:
# If this property has a more detailed definition in the model, # if prop.name in self.model:
# copy over the information: # model_prop = self.model[prop.name]
# # The information must be missing, we don't want to overwrite it accidentally:
if isinstance(model_prop, db.RecordType): # if prop.datatype is not None and prop.datatype != model_prop.datatype:
# in this case the datatype equals the name of the record type: # # breakpoint()
prop.datatype = prop.name # raise RuntimeError("datatype must not be set, here. This is probably a bug.")
else: # if prop.unit is not None and prop.unit != model_prop.unit:
prop.datatype = model_prop.datatype # # continue
prop.unit = model_prop.unit # raise RuntimeError("unit must not be set, here. This is probably a bug.")
prop.description = model_prop.description # if prop.description is not None and prop.description != model_prop.description:
# # continue
# raise RuntimeError("description must not be set, here. This is probably a bug.")
#
# # 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
# prop.description = model_prop.description
return DataModel(self.model.values()) return DataModel(self.model.values())
......
...@@ -27,6 +27,8 @@ from caosadvancedtools.models.parser import (TwiceDefinedException, ...@@ -27,6 +27,8 @@ from caosadvancedtools.models.parser import (TwiceDefinedException,
parse_model_from_string, parse_model_from_string,
parse_model_from_yaml) parse_model_from_yaml)
from unittests.mock import Mock
from linkahead.apiutils import compare_entities from linkahead.apiutils import compare_entities
...@@ -645,7 +647,7 @@ RT2: ...@@ -645,7 +647,7 @@ RT2:
}""" }"""
def test_comparison_yaml_model(): def test_comparison_yaml_model(capfd):
""" """
Test for this issue: Test for this issue:
https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/130 https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/130
...@@ -707,7 +709,24 @@ test_reference: ...@@ -707,7 +709,24 @@ test_reference:
c2 = compare_entities(model["RT1"], entities[1]) c2 = compare_entities(model["RT1"], entities[1])
c3 = compare_entities(model["RT2"], entities[2]) c3 = compare_entities(model["RT2"], entities[2])
c4 = compare_entities(model["test_reference"], entities[3]) c4 = compare_entities(model["test_reference"], entities[3])
for cs in (c1, c2, c3, c4):
assert "id" not in cs[0]
assert "id" in cs[1]
mq = Mock()
def mq_init(self, query):
self.query = query
def mq_execute(self, unique=True):
pass
mq.__init__ = mq_init
mq.execute.side_effect = mq_execute
caosadvancedtools.models.parser.db.Query = mq
model.sync_data_model(True, True)
stdout, stderr = capfd.readouterr()
# TODO: test that there were no changes required
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment