Skip to content
Snippets Groups Projects

Compare_entities diff uses id instead of name where needed

Merged I. Nüske requested to merge f-bug-fit-94-compare-properties-with-id into dev
All threads resolved!
Files
2
+ 14
8
@@ -196,16 +196,20 @@ def compare_entities(entity0: Optional[Entity] = None,
that are missing in the other entity, and the 'properties' dict contains
properties and SPECIAL_ATTRIBUTES if they are missing or different from
their counterparts in the other entity.
The key used to represent a parent or property is the entities name if the
The key used to represent a parent in the parent list or a
property in the property dictionary is the entity's name if the
name is present for both compared entities, the id otherwise.
The value of the properties dict for each listed property is again a dict
detailing the differences between this property and its counterpart.
The characteristics that are checked to determine whether two properties
match are the following:
- datatype
- importance
- value
- datatype
- importance
- value
If any of these characteristics differ for a property, the respective
string (datatype, importance, value) is added as a key to the dict of the
property with its value being the characteristics value,
@@ -244,6 +248,7 @@ def compare_entities(entity0: Optional[Entity] = None,
entity and an int or str also checks whether
the int/str matches the name or id of the
entity, so Entity(id=100) == 100 == "100".
"""
# ToDo: Discuss intended behaviour
# Questions that need clarification:
@@ -379,7 +384,8 @@ def compare_entities(entity0: Optional[Entity] = None,
# compare properties
for prop in entity0.properties:
key = prop.name if prop.name is not None else prop.id # ToDo: Would making id default break anything?
# ToDo: Would making id default break anything?
key = prop.name if prop.name is not None else prop.id
matching = entity1.properties.filter(prop)
if len(matching) == 0:
# entity1 has prop, entity0 does not
@@ -387,7 +393,7 @@ def compare_entities(entity0: Optional[Entity] = None,
elif len(matching) == 1:
# It's possible that prop has name and id, but match only has id
key = prop.name if (prop.name is not None and
matching[0].name is not None) else prop.id
matching[0].name == prop.name) else prop.id
diff[0]["properties"][key] = {}
diff[1]["properties"][key] = {}
propdiff = (diff[0]["properties"][key],
@@ -432,7 +438,7 @@ def compare_entities(entity0: Optional[Entity] = None,
# we have not yet compared properties that do not exist in entity0
for prop in entity1.properties:
key = prop.name if prop.name is not None else prop.id # ToDo: Would making id default break anything?
key = prop.name if prop.name is not None else prop.id
# check how often the property appears in entity0
num_prop_in_ent0 = len(entity0.properties.filter(prop))
if num_prop_in_ent0 == 0:
@@ -448,7 +454,7 @@ def compare_entities(entity0: Optional[Entity] = None,
for index, parents, other_entity in [(0, entity0.parents, entity1),
(1, entity1.parents, entity0)]:
for parent in parents:
key = parent.name if parent.name is not None else parent.id # ToDo: Would making id default break anything?
key = parent.name if parent.name is not None else parent.id
matching = other_entity.parents.filter(parent)
if len(matching) == 0:
diff[index]["parents"].append(key)
Loading