From bdc88dfcbf8371f14b07fac9eba71d57bc3f58c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Wed, 6 Nov 2024 10:38:26 +0100 Subject: [PATCH] TST: add test cases for compare entities --- unittests/test_apiutils.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py index 3877c09e..33159c97 100644 --- a/unittests/test_apiutils.py +++ b/unittests/test_apiutils.py @@ -111,13 +111,25 @@ def test_compare_entities(): r2.add_property("tester", ) r1.add_property("tests_234234", value=45) r2.add_property("tests_TT", value=45) + r1.add_property("datatype", value=45, datatype=db.INTEGER) + r2.add_property("datatype", value=45) + r1.add_property("entity_id", value=2) + r2.add_property("entity_id", value=24) + r1.add_property("entity_mix_e", value=2) + r2.add_property("entity_mix_e", value=db.Entity(id=2)) + r1.add_property("entity_mix_d", value=22) + r2.add_property("entity_mix_d", value=db.Entity(id=2)) + r1.add_property("entity_Ent_e", value=db.Entity(id=2)) + r2.add_property("entity_Ent_e", value=db.Entity(id=2)) + r1.add_property("entity_Ent_d", value=db.Entity(id=2)) + r2.add_property("entity_Ent_d", value=db.Entity(id=22)) diff_r1, diff_r2 = compare_entities(r1, r2) assert len(diff_r1["parents"]) == 1 assert len(diff_r2["parents"]) == 0 - assert len(diff_r1["properties"]) == 4 - assert len(diff_r2["properties"]) == 4 + assert len(diff_r1["properties"]) == 10 + assert len(diff_r2["properties"]) == 10 assert "test" not in diff_r1["properties"] assert "test" not in diff_r2["properties"] @@ -135,6 +147,19 @@ def test_compare_entities(): assert "tests_TT" in diff_r2["properties"] + assert "entity_id" in diff_r1["properties"] + assert "entity_id" in diff_r2["properties"] + + assert "entity_mix_e" in diff_r1["properties"] + assert "entity_mix_e" in diff_r2["properties"] + assert "entity_Ent_e" in diff_r1["properties"] + assert "entity_Ent_e" in diff_r2["properties"] + + assert "entity_mix_d" in diff_r1["properties"] + assert "entity_mix_d" in diff_r2["properties"] + assert "entity_Ent_d" in diff_r1["properties"] + assert "entity_Ent_d" in diff_r2["properties"] + def test_compare_entities_units(): r1 = db.Record() r2 = db.Record() @@ -572,12 +597,19 @@ B: something else""" # test whether an id is correctly overwritten by an entity without id recA = db.Record().add_parent("A").add_property(name="B", value=112) - newRec = db.Record() + newRec = db.Record().add_parent("B").add_property("c") recB = db.Record().add_parent("A").add_property(name="B", value=newRec) merge_entities(recA, recB, force=True) assert recA.get_property("B").value == newRec + recA = db.Record().add_parent("A").add_property(name="B", value=[112], + datatype=db.LIST("B")) + recB = db.Record().add_parent("A").add_property(name="B", value=[newRec], datatype=db.LIST(db.REFERENCE)) + + merge_entities(recA, recB, force=True) + assert recA.get_property("B").value == [newRec] + def test_merge_missing_list_datatype_82(): """Merging two properties, where the list-valued one has no datatype.""" -- GitLab