Skip to content
Snippets Groups Projects
Commit a10bc1ed authored by I. Nüske's avatar I. Nüske
Browse files

TST: Extend compare_entities tests

parent d8af8e21
No related branches found
No related tags found
3 merge requests!159Release 0.16.o,!158F list filter,!157compare entities and parent/property lists
Pipeline #57335 passed with warnings
...@@ -251,12 +251,16 @@ def compare_entities(entity0: Optional[Entity] = None, ...@@ -251,12 +251,16 @@ def compare_entities(entity0: Optional[Entity] = None,
# - Should there be a more detailed comparison of parents without id? # - Should there be a more detailed comparison of parents without id?
# - Revisit filter - do we care about RecordType when matching? # - Revisit filter - do we care about RecordType when matching?
# How to treat None? # How to treat None?
# - Should matching of parents also take the recordtype into account
# for parents that have a name but no id?
# Suggestions for enhancements: # Suggestions for enhancements:
# - For the comparison of entities in value and properties, consider # - For the comparison of entities in value and properties, consider
# keeping a list of traversed entities, not only look at first layer # keeping a list of traversed entities, not only look at first layer
# - Make the empty_diff functionality faster by adding a parameter to # - Make the empty_diff functionality faster by adding a parameter to
# this function so that it returns after the first found difference? # this function so that it returns after the first found difference?
# - Add parameter to restrict diff to some characteristics # - Add parameter to restrict diff to some characteristics
# - Implement comparison of date where one is a string and the other is
# datetime
if entity0 is None and old_entity is None: if entity0 is None and old_entity is None:
raise ValueError("Please provide the first entity as first argument (`entity0`)") raise ValueError("Please provide the first entity as first argument (`entity0`)")
if entity1 is None and new_entity is None: if entity1 is None and new_entity is None:
......
...@@ -438,20 +438,43 @@ def test_compare_entities_battery(): ...@@ -438,20 +438,43 @@ def test_compare_entities_battery():
t8 = db.Property(**alt_settings).add_parent(par3).add_property(prop3) t8 = db.Property(**alt_settings).add_parent(par3).add_property(prop3)
diffs_0 = compare_entities(t7, t8), compare_entities(t7, t8, True) diffs_0 = compare_entities(t7, t8), compare_entities(t7, t8, True)
diffs_1 = compare_entities(t8, t7)[::-1], compare_entities(t8, t7, True)[::-1] diffs_1 = compare_entities(t8, t7)[::-1], compare_entities(t8, t7, True)[::-1]
#assert diffs_0 == diffs_1 assert diffs_0 == diffs_1
prop_settings = {"datatype": db.REFERENCE, "description": "desc of prop", prop_settings = {"datatype": db.REFERENCE, "description": "desc of prop",
"value": db.Record().add_parent(par3), "unit": '°'} "value": db.Record().add_parent(par3), "unit": '°'}
t1.add_property(db.Property(name="description", **prop_settings)) t1.add_property(db.Property(name="description", **prop_settings))
t2.add_property(db.Property(name="description", **prop_settings)) t2.add_property(db.Property(name="description", **prop_settings))
# try: # Order invariance for multi-property - either both fail or same result
# diffs_0 = compare_entities(t1, t2), compare_entities(t1, t2, True) try:
# except Exception as e: diffs_0 = compare_entities(t1, t2), compare_entities(t1, t2, True)
# diffs_0 = type(e) except Exception as e:
# try: diffs_0 = type(e)
# diffs_1 = compare_entities(t2, t1)[::-1], compare_entities(t2, t1, True)[::-1] try:
# except Exception as e: diffs_1 = compare_entities(t2, t1)[::-1], compare_entities(t2, t1, True)[::-1]
# diffs_1 = type(e) except Exception as e:
# assert diffs_0 == diffs_1 diffs_1 = type(e)
assert diffs_0 == diffs_1
# Property types
t09, t10 = db.RecordType(), db.RecordType()
for t, ex in [(db.INTEGER, [-12, 0]), (db.DATETIME, ["2030-01-01", "1012-02-29"]),
(db.DOUBLE, [13.23, 7.1]), (db.BOOLEAN, [True, False])]:
t09.add_property(db.Property(name=f"{t}:{ex[0]}", datatype=t, value=ex[0]))
t10.add_property(db.Property(name=f"{t}:{ex[0]}", datatype=t, value=ex[0]))
t09.add_property(name=f"{t}:{ex[1]}", datatype=t, value=ex[1])
t10.add_property(name=f"{t}:{ex[1]}", datatype=t, value=ex[1])
assert empty_diff(t09, t10)
t09.add_property(name=f"diff", value=1)
t10.add_property(name=f"diff", value=2)
assert not empty_diff(t09, t10)
# Default values
t09, t10 = db.Record(), db.Record()
t09.add_property(db.Property(name=f"A1"), value="A")
t10.add_property(name=f"A1", value="A")
t09.add_property(db.Property(id=12, name=f"A2"), value="A")
t10.add_property(id=12, name=f"A2", value="A")
t09.add_property(db.Property(id=15), value="A")
t10.add_property(id=15, value="A")
assert empty_diff(t09, t10)
# ToDo: extended tests for references
def test_compare_special_properties(): def test_compare_special_properties():
......
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