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
052034ff
Commit
052034ff
authored
Nov 22, 2021
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: added tests for identifiable adapter
parent
45458794
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/identifiable_adapters.py
+26
-2
26 additions, 2 deletions
src/newcrawler/identifiable_adapters.py
tests/test_tool.py
+70
-3
70 additions, 3 deletions
tests/test_tool.py
with
96 additions
and
5 deletions
src/newcrawler/identifiable_adapters.py
+
26
−
2
View file @
052034ff
...
...
@@ -196,8 +196,9 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return
False
for
prop
in
registered_identifiable
.
properties
:
if
record
.
get_property
(
name
=
prop
.
name
)
is
None
:
if
record
.
get_property
(
prop
.
name
)
is
None
:
return
False
return
True
def
get_registered_identifiable
(
self
,
record
:
db
.
Record
):
identifiable_candidates
=
[]
...
...
@@ -210,6 +211,29 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return
None
return
identifiable_candidates
[
0
]
@staticmethod
def
check_record
(
record
:
db
.
Record
,
identifiable
:
db
.
Record
):
if
len
(
identifiable
.
parents
)
!=
1
:
raise
RuntimeError
(
"
Multiple parents for identifiables not supported.
"
)
if
not
record
.
has_parent
(
identifiable
.
parents
[
0
]):
return
False
for
prop
in
identifiable
.
properties
:
prop_record
=
record
.
get_property
(
prop
.
name
)
if
prop_record
is
None
:
return
False
if
prop
.
value
!=
prop_record
.
value
:
return
False
return
True
def
retrieve_identified_record
(
self
,
identifiable
:
db
.
Record
):
pass
candidates
=
[]
for
record
in
self
.
_records
:
if
self
.
check_record
(
record
,
identifiable
):
candidates
.
append
(
record
)
if
len
(
candidates
)
>
1
:
raise
RuntimeError
(
"
Identifiable was not defined unambigiously.
"
)
if
len
(
candidates
)
==
0
:
return
None
return
candidates
[
0
]
This diff is collapsed.
Click to expand it.
tests/test_tool.py
+
70
−
3
View file @
052034ff
...
...
@@ -11,6 +11,8 @@ from os.path import join, dirname, basename
import
yaml
import
caosdb
as
db
from
pytest
import
raises
# Some notes:
# Track provenance information in two ways:
# - DONE: provenance in structure elements and converters for properties of records
...
...
@@ -162,11 +164,76 @@ def test_crawler_update_list():
# assert len(crawler.updateList) == 8
ident
=
LocalStorageIdentifiableAdapter
()
ident
.
get_records
().
extend
(
crawler
.
updateList
)
ident
.
store_state
(
rfp
(
"
records.xml
"
))
#
ident.restore_state(rfp("records.xml"))
#
ident.get_records().extend(crawler.updateList)
#
ident.store_state(rfp("records.xml"))
ident
.
restore_state
(
rfp
(
"
records.xml
"
))
assert
len
(
ident
.
get_records
())
==
len
(
crawler
.
updateList
)
ident
.
register_identifiable
(
"
Person
"
,
db
.
RecordType
()
.
add_parent
(
name
=
"
Person
"
)
.
add_property
(
name
=
"
first_name
"
)
.
add_property
(
name
=
"
last_name
"
))
ident
.
register_identifiable
(
"
Measurement
"
,
db
.
RecordType
()
.
add_parent
(
name
=
"
Measurement
"
)
.
add_property
(
name
=
"
identifier
"
)
.
add_property
(
name
=
"
date
"
)
.
add_property
(
name
=
"
project
"
))
ident
.
register_identifiable
(
"
Project
"
,
db
.
RecordType
()
.
add_parent
(
name
=
"
Project
"
)
.
add_property
(
name
=
"
date
"
)
.
add_property
(
name
=
"
identifier
"
))
curind
=
0
r
=
ident
.
get_records
()
id_r0
=
ident
.
get_identifiable
(
r
[
0
])
assert
r
[
curind
].
parents
[
0
].
name
==
id_r0
.
parents
[
0
].
name
assert
r
[
curind
].
get_property
(
"
first_name
"
).
value
==
id_r0
.
get_property
(
"
first_name
"
).
value
assert
r
[
curind
].
get_property
(
"
last_name
"
).
value
==
id_r0
.
get_property
(
"
last_name
"
).
value
assert
len
(
r
[
curind
].
parents
)
==
1
assert
len
(
id_r0
.
parents
)
==
1
assert
len
(
r
[
curind
].
properties
)
==
2
assert
len
(
id_r0
.
properties
)
==
2
with
raises
(
RuntimeError
,
match
=
"
.*unambigiously.*
"
):
ident
.
retrieve_identified_record
(
id_r0
)
# clean record list:
recordlist
=
ident
.
get_records
()
for
i
in
range
(
len
(
recordlist
)
-
1
,
1
,
-
1
):
if
recordlist
[
i
].
parents
[
0
].
name
==
"
Person
"
:
del
recordlist
[
i
]
idr_r0_test
=
ident
.
retrieve_identified_record
(
id_r0
)
idr_r0
=
ident
.
retrieve_identifiable
(
r
[
curind
])
assert
idr_r0
==
idr_r0_test
curind
+=
1
r
=
ident
.
get_records
()
id_r1
=
ident
.
get_identifiable
(
r
[
curind
])
print
(
r
[
curind
])
print
(
id_r1
)
assert
r
[
curind
].
parents
[
0
].
name
==
id_r1
.
parents
[
0
].
name
assert
r
[
curind
].
get_property
(
"
identifier
"
).
value
==
id_r1
.
get_property
(
"
identifier
"
).
value
assert
r
[
curind
].
get_property
(
"
date
"
).
value
==
id_r1
.
get_property
(
"
date
"
).
value
assert
r
[
curind
].
get_property
(
"
project
"
).
value
==
id_r1
.
get_property
(
"
project
"
).
value
assert
len
(
r
[
curind
].
parents
)
==
1
assert
len
(
id_r1
.
parents
)
==
1
assert
len
(
r
[
curind
].
properties
)
==
5
assert
len
(
id_r1
.
properties
)
==
3
idr_r1_test
=
ident
.
retrieve_identified_record
(
id_r1
)
idr_r1
=
ident
.
retrieve_identifiable
(
r
[
curind
])
assert
idr_r1
==
idr_r1_test
assert
idr_r1
!=
idr_r0
assert
idr_r1_test
!=
idr_r0_test
assert
len
(
idr_r1
.
properties
)
==
5
assert
r
[
curind
].
get_property
(
"
responsible
"
).
value
==
idr_r1
.
get_property
(
"
responsible
"
).
value
assert
r
[
curind
].
get_property
(
"
description
"
).
value
==
idr_r1
.
get_property
(
"
description
"
).
value
def
test_provenance_debug_data
():
crawler
=
Crawler
(
debug
=
True
)
...
...
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