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
Branches
Tags
2 merge requests!159Release 0.16.o,!154Added the possibility to use custom labels instead of 'old' and 'new'
Checking pipeline status
...@@ -447,28 +447,46 @@ def compare_entities(entity0: Optional[Entity] = None, ...@@ -447,28 +447,46 @@ def compare_entities(entity0: Optional[Entity] = None,
return diff return diff
def empty_diff(old_entity: Entity, new_entity: Entity, def empty_diff(entity0: Entity,
entity1: Entity,
compare_referenced_records: bool = False, 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 """Check whether the `compare_entities` found any differences between
old_entity and new_entity. entity0 and entity1.
Parameters Parameters
---------- ----------
old_entity, new_entity : Entity entity0, entity1 : Entity
Entities to be compared Entities to be compared
compare_referenced_records : bool, optional compare_referenced_records : bool, optional
Whether to compare referenced records in case of both, `old_entity` and Whether to compare referenced records in case of both, `entity0` and
`new_entity`, have the same reference properties and both have a Record `entity1`, have the same reference properties and both have a Record
object as value. object as value.
entity_name_id_equivalency : bool, optional entity_name_id_equivalency : bool, optional
If set to True, the comparison between an entity and an int or str also 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 checks whether the int/str matches the name or id of the entity, so
Entity(id=100) == 100 == "100". Entity(id=100) == 100 == "100".
""" """
olddiff, newdiff = compare_entities(old_entity, new_entity, if entity0 is None and old_entity is None:
compare_referenced_records, entity_name_id_equivalency) raise ValueError("Please provide the first entity as first argument (`entity0`)")
for diff in [olddiff, newdiff]: 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"]: for key in ["parents", "properties"]:
if len(diff[key]) > 0: if len(diff[key]) > 0:
# There is a difference somewhere in the diff # 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], ...@@ -641,11 +659,11 @@ def describe_diff(entity0_diff: dict[str, Any], entity1_diff: dict[str, Any],
entity0_diff: dict[str, Any] entity0_diff: dict[str, Any]
First element of the tuple output of :func:`compare_entities`. 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] entity1_diff: dict[str, Any]
Second element of the tuple output of :func:`compare_entities`. 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] name: Optional[str]
...@@ -655,10 +673,10 @@ def describe_diff(entity0_diff: dict[str, Any], entity1_diff: dict[str, Any], ...@@ -655,10 +673,10 @@ def describe_diff(entity0_diff: dict[str, Any], entity1_diff: dict[str, Any],
Default None. Not used anymore. Default None. Not used anymore.
label_e0: str 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 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: Returns:
-------- --------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment