Skip to content
Snippets Groups Projects
Commit bf7e3f5a authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

ENH: fixed bugs in compare function and enhanced the description of a diff of two records

parent cf3eecec
No related branches found
No related tags found
No related merge requests found
......@@ -550,6 +550,12 @@ def compare_entities(old_entity, new_entity):
except BaseException:
new_entity_attr_exists = False
if old_entity_attr_exists and (oldattr == "" or oldattr is None):
old_entity_attr_exists = False
if new_entity_attr_exists and (newattr == "" or newattr is None):
new_entity_attr_exists = False
if not old_entity_attr_exists and not new_entity_attr_exists:
continue
......@@ -571,6 +577,7 @@ def compare_entities(old_entity, new_entity):
olddiff["properties"][prop.name] = {}
elif len(matching) == 1:
newdiff["properties"][prop.name] = {}
olddiff["properties"][prop.name] = {}
if (old_entity.get_importance(prop.name) !=
new_entity.get_importance(prop.name)):
......@@ -585,6 +592,12 @@ def compare_entities(old_entity, new_entity):
olddiff["properties"][prop.name]["datatype"] = prop.datatype
newdiff["properties"][prop.name]["datatype"] = \
matching[0].datatype
if (len(newdiff["properties"][prop.name]) == 0
and len(olddiff["properties"][prop.name]) == 0):
newdiff["properties"].pop(prop.name)
olddiff["properties"].pop(prop.name)
else:
raise NotImplementedError()
......@@ -605,10 +618,10 @@ def compare_entities(old_entity, new_entity):
return (olddiff, newdiff)
def describe_diff(olddiff, newdiff, as_update=True):
description = "## Difference between the old and the new version of {}\n\n"
def describe_diff(olddiff, newdiff, name=None, as_update=True):
description = ""
for attr in list(set(list(olddiff.keys)+list(newdiff.keys))):
for attr in list(set(list(olddiff.keys())+list(newdiff.keys()))):
if attr == "parents" or attr == "properties":
continue
description += "{} differs:\n".format(attr)
......@@ -625,12 +638,22 @@ def describe_diff(olddiff, newdiff, as_update=True):
description += ("Parents that are only in the new version:\n"
+ ", ".join(olddiff["parents"]))
for prop in list(set(list(olddiff["properties"].keys)
+ list(newdiff["properties"].keys))):
for prop in list(set(list(olddiff["properties"].keys())
+ list(newdiff["properties"].keys()))):
description += "property {} differs:\n".format(prop)
description += "old version: {}\n".format(
olddiff["properties"][prop] if prop
in olddiff["properties"] else "has none")
description += "new version: {}\n\n".format(
newdiff["properties"][prop] if prop
in newdiff["properties"] else "has none")
if prop not in olddiff["properties"]:
description += "it does not exist in the old version: \n"
elif prop not in newdiff["properties"]:
description += "it does not exist in the new version: \n"
else:
description += "old version: {}\n".format(
olddiff["properties"][prop])
description += "new version: {}\n\n".format(
newdiff["properties"][prop])
if description != "":
description = ("## Difference between the old and the new "
"version of {}\n\n".format(name))+description
return description
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment