Skip to content
Snippets Groups Projects
Commit d3c6f56e authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

test(apiutils): added a unittest for describe_diff function

parent ef3ecc9b
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 #56805 passed with warnings
......@@ -17,6 +17,6 @@ max-line-length=100
[pytest]
testpaths = unittests
xfail_strict = True
addopts = -x -vv --cov=caosdb
addopts = -x -vv --cov=linkahead
pythonpath = src
#
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Alexander Schlemmer <a.schlemmer@indiscale.com>
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2022 Florian Spreckelsen <f.spreckelsen@indiscale.com>
# Copyright (C) 2022 Daniel Hornung <d.hornung@indiscale.com>
......@@ -31,7 +32,8 @@ import linkahead.apiutils
import pytest
from linkahead.apiutils import (EntityMergeConflictError, apply_to_ids,
compare_entities, create_id_query, empty_diff,
merge_entities, resolve_reference)
merge_entities, resolve_reference,
describe_diff)
from linkahead.common.models import SPECIAL_ATTRIBUTES
......@@ -627,3 +629,46 @@ def test_merge_id_with_resolved_entity():
merge_entities(recA, recB, merge_id_with_resolved_entity=True)
assert recA.get_property(rtname).value == [ref_id, ref_id*2]
assert recA.get_property(rtname).value == recB.get_property(rtname).value
def test_describe_diff():
recA = db.Record()
recA.add_property(name="propA", value=2)
recA.add_property(name="propB", value=2)
recA.add_property(name="propD", value=-273, unit="K")
recB = db.Record()
recB.add_property(name="propA", value=2)
recB.add_property(name="propB", value=12)
recB.add_property(name="propC", value="cool 17")
recB.add_property(name="propD", value=-273, unit="°C")
diff = compare_entities(recA, recB)
diffout = describe_diff(*diff)
assert diffout.startswith("## Difference between the old version and the new version of None")
# The output of the describe_diff function is currently not ordered (e.g. by name of the property)
# so we cannot just compare a well-defined output string.
assert "it does not exist in the old version:" in diffout
assert "old version: {'value': 2}" in diffout
assert "new version: {'value': 12}" in diffout
assert "old version: {'unit': 'K'}" in diffout
assert "new version: {'unit': '°C'}" in diffout
diffout = describe_diff(*diff, name="Entity")
assert diffout.startswith("## Difference between the old version and the new version of Entity")
diffout = describe_diff(*diff, label_old="recA", label_new="recB")
assert "recA: {'value': 2}" in diffout
assert "recB: {'value': 12}" in diffout
assert "recA: {'unit': 'K'}" in diffout
assert "recB: {'unit': '°C'}" in diffout
assert "it does not exist in the recA:" in diffout
assert "old" not in diffout
assert "new" not in diffout
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment