From 8f6d352819c2773726b23d6db4f3723b8925b092 Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <alexander@mail-schlemmer.de> Date: Tue, 12 Apr 2022 15:37:42 +0200 Subject: [PATCH] DOC: updated merge_entities docstr to note that the function is currently experimental --- src/caosdb/apiutils.py | 7 +++++++ unittests/test_apiutils.py | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py index b1721e25..08f31daa 100644 --- a/src/caosdb/apiutils.py +++ b/src/caosdb/apiutils.py @@ -39,6 +39,8 @@ from caosdb.common.models import (Container, Entity, File, Property, Query, Record, RecordType, execute_query, get_config, SPECIAL_ATTRIBUTES) +import logging + def new_record(record_type, name=None, description=None, tempid=None, insert=False, **kwargs): @@ -689,8 +691,13 @@ def merge_entities(entity_a: Entity, entity_b: Entity): The merge operation is done in place. Returns entity_a. + + WARNING: This function is currently experimental and insufficiently tested. Use with care. """ + logging.warning( + "This function is currently experimental and insufficiently tested. Use with care.") + # Compare both entities: diff_r1, diff_r2 = compare_entities(entity_a, entity_b) diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py index e75f6049..13603f4c 100644 --- a/unittests/test_apiutils.py +++ b/unittests/test_apiutils.py @@ -33,6 +33,8 @@ import caosdb.apiutils from caosdb.apiutils import (apply_to_ids, compare_entities, create_id_query, resolve_reference, merge_entities) +from caosdb.common.models import SPECIAL_ATTRIBUTES + from .test_property import testrecord import pytest @@ -247,12 +249,13 @@ def test_copy_entities(): assert c.name == "A" assert c.role == r.role assert c.parents[0].name == "B" - # Currently parents and properties are always individual to a copy: - assert c.parents[0] != r.parents[0] + # parent and property objects are not shared among copy and original: + assert c.parents[0] is not r.parents[0] for i in [0, 1]: - assert c.properties[i] != r.properties[i] - assert c.properties[i].value == r.properties[i].value + assert c.properties[i] is not r.properties[i] + for special in SPECIAL_ATTRIBUTES: + assert getattr(c.properties[i], special) == getattr(r.properties[i], special) assert c.get_importance(c.properties[i]) == r.get_importance(r.properties[i]) -- GitLab