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

TST: new test for check_identical function

parent f7dfe888
No related branches found
No related tags found
1 merge request!53Release 0.1
......@@ -52,10 +52,10 @@ def check_identical(record1: db.Entity, record2: db.Entity):
- If one of the entities has additional parents or additional properties -> not identical
- If the value of one of the properties differs -> not identical
- If datatype, importance or unit are reported different for a property by compare_entities
return "not_identical" only if these attributes are set explicitely by record2.
return "not_identical" only if these attributes are set explicitely by record1.
Ignore the difference otherwise.
- If description, name, id or path appear in list of differences -> not identical.
- If file, checksum, size appear -> Only different, if explicitely set by record2.
- If file, checksum, size appear -> Only different, if explicitely set by record1.
record1 serves as the reference, so datatype, importance and unit checks are carried
out using the attributes from record1. In that respect, the function is not symmetrical
......@@ -72,6 +72,7 @@ def check_identical(record1: db.Entity, record2: db.Entity):
return False
for special_property in SPECIAL_PROPERTIES_NOT_STRICT:
if special_property in comp[0]:
attr_val = comp[0][special_property]
other_attr_val = (comp[1][special_property]
if special_property in comp[1] else None)
......@@ -366,7 +367,7 @@ class Crawler(object):
# information
# Update an (local) identified record that will be inserted
newrecord = self.get_identified_record_from_local_cache(record)
breakpoint()
# breakpoint()
# self.copy_attributes(fro=record, to=newrecord)
# Bend references to the other object
# TODO refactor this
......
#!/bin/python
# Tests for entity comparison
# A. Schlemmer, 06/2021
import caosdb as db
import pytest
from pytest import raises
from newcrawler.crawl import check_identical
def test_compare_entities():
record1 = db.Record()
record2 = db.Record()
assert check_identical(record1, record2)
record1.add_property(name="type", value="int")
assert not check_identical(record1, record2)
assert not check_identical(record2, record1)
record2.add_property(name="type", value="int")
assert check_identical(record1, record2)
record2.get_property("type").value = "int2"
assert not check_identical(record1, record2)
record2.get_property("type").value = 4
assert not check_identical(record1, record2)
record2.get_property("type").value = "int"
assert check_identical(record1, record2)
record2.add_parent(db.RecordType(name="Parent"))
assert not check_identical(record1, record2)
record1.add_parent(db.RecordType(name="Parent"))
# This is confusing, but needed:
record1.add_property(name="field_with_type", value=42, datatype=db.INTEGER)
record2.add_property(name="field_with_type", value=42)
assert not check_identical(record1, record2) # not identical, because record1 sets the datatype
assert check_identical(record2, record1) # identical, because record2 sets the datatype
record2.get_property("field_with_type").datatype = db.INTEGER
assert check_identical(record1, record2)
assert check_identical(record2, record1)
record2.get_property("field_with_type").datatype = db.DOUBLE
assert not check_identical(record1, record2)
assert not check_identical(record2, record1)
# TODO: report this as a hacky workaround (for setting datatype from double to integer):
record2.get_property("field_with_type").datatype = db.TEXT
record2.get_property("field_with_type").datatype = db.INTEGER
assert check_identical(record1, record2)
assert check_identical(record2, record1)
record1.description = "bla bla"
assert not check_identical(record1, record2)
assert not check_identical(record2, record1)
record2.description = "bla bla bla"
assert not check_identical(record1, record2)
assert not check_identical(record2, record1)
record2.description = "bla bla"
assert check_identical(record1, record2)
assert check_identical(record2, record1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment