Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
823792e4
Commit
823792e4
authored
Jan 28, 2022
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: new test for check_identical function
parent
f7dfe888
No related branches found
No related tags found
1 merge request
!53
Release 0.1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/newcrawler/crawl.py
+9
-8
9 additions, 8 deletions
src/newcrawler/crawl.py
unittests/test_entity_comparison.py
+64
-0
64 additions, 0 deletions
unittests/test_entity_comparison.py
with
73 additions
and
8 deletions
src/newcrawler/crawl.py
+
9
−
8
View file @
823792e4
...
...
@@ -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 record
2
.
return
"
not_identical
"
only if these attributes are set explicitely by record
1
.
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 record
2
.
- If file, checksum, size appear -> Only different, if explicitely set by record
1
.
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
...
...
This diff is collapsed.
Click to expand it.
unittests/test_entity_comparison.py
0 → 100644
+
64
−
0
View file @
823792e4
#!/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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment