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

MAINT: rename arguments of empty diff

parent 62cdd301
No related branches found
No related tags found
2 merge requests!159Release 0.16.o,!154Added the possibility to use custom labels instead of 'old' and 'new'
Pipeline #57462 passed with warnings
......@@ -447,28 +447,46 @@ def compare_entities(entity0: Optional[Entity] = None,
return diff
def empty_diff(old_entity: Entity, new_entity: Entity,
def empty_diff(entity0: Entity,
entity1: Entity,
compare_referenced_records: bool = False,
entity_name_id_equivalency: bool = False) -> bool:
entity_name_id_equivalency: bool = False,
old_entity: Optional[Entity] = None,
new_entity: Optional[Entity] = None,
) -> bool:
"""Check whether the `compare_entities` found any differences between
old_entity and new_entity.
entity0 and entity1.
Parameters
----------
old_entity, new_entity : Entity
entity0, entity1 : Entity
Entities to be compared
compare_referenced_records : bool, optional
Whether to compare referenced records in case of both, `old_entity` and
`new_entity`, have the same reference properties and both have a Record
Whether to compare referenced records in case of both, `entity0` and
`entity1`, have the same reference properties and both have a Record
object as value.
entity_name_id_equivalency : bool, optional
If set to True, the comparison between an 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".
"""
olddiff, newdiff = compare_entities(old_entity, new_entity,
compare_referenced_records, entity_name_id_equivalency)
for diff in [olddiff, newdiff]:
if entity0 is None and old_entity is None:
raise ValueError("Please provide the first entity as first argument (`entity0`)")
if entity1 is None and new_entity is None:
raise ValueError("Please provide the second entity as second argument (`entity1`)")
if old_entity is not None:
warnings.warn("Please use 'entity0' instead of 'old_entity'.", DeprecationWarning)
if entity0 is not None:
raise ValueError("You cannot use both entity0 and old_entity")
entity0 = old_entity
if new_entity is not None:
warnings.warn("Please use 'entity1' instead of 'new_entity'.", DeprecationWarning)
if entity1 is not None:
raise ValueError("You cannot use both entity1 and new_entity")
entity1 = new_entity
e0diff, e1diff = compare_entities(entity0, entity1, compare_referenced_records,
entity_name_id_equivalency)
for diff in [e0diff, e1diff]:
for key in ["parents", "properties"]:
if len(diff[key]) > 0:
# There is a difference somewhere in the diff
......@@ -641,11 +659,11 @@ def describe_diff(entity0_diff: dict[str, Any], entity1_diff: dict[str, Any],
entity0_diff: dict[str, Any]
First element of the tuple output of :func:`compare_entities`.
This is referred to as the "old" version.
This is referred to as the "first" version.
entity1_diff: dict[str, Any]
Second element of the tuple output of :func:`compare_entities`.
This is referred to as the "new" version.
This is referred to as the "second" version.
name: Optional[str]
......@@ -655,10 +673,10 @@ def describe_diff(entity0_diff: dict[str, Any], entity1_diff: dict[str, Any],
Default None. Not used anymore.
label_e0: str
Can be used to set a custom label for the diff that is associated with the old entity.
Can be used to set a custom label for the diff that is associated with the first entity.
label_e1: str
Can be used to set a custom label for the diff that is associated with the new entity.
Can be used to set a custom label for the diff that is associated with the second entity.
Returns:
--------
......
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