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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
be7f26b1
Commit
be7f26b1
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
WIP
parent
f464b3db
No related branches found
No related tags found
2 merge requests
!71
REL: RElease v0.2.0
,
!5
FIX: use identifiable instead of record
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
src/newcrawler/crawl.py
+1
-0
1 addition, 0 deletions
src/newcrawler/crawl.py
src/newcrawler/identifiable_adapters.py
+8
-18
8 additions, 18 deletions
src/newcrawler/identifiable_adapters.py
unittests/test_tool.py
+36
-20
36 additions, 20 deletions
unittests/test_tool.py
with
47 additions
and
39 deletions
.gitignore
+
2
−
1
View file @
be7f26b1
src/newcrawler.egg-info/
__pycache__
unittests/provenance.yml
.coverage
TAGS
src/.coverage
\ No newline at end of file
src/.coverage
This diff is collapsed.
Click to expand it.
src/newcrawler/crawl.py
+
1
−
0
View file @
be7f26b1
...
...
@@ -442,6 +442,7 @@ class Crawler(object):
identified_records
=
[
self
.
identifiableAdapter
.
retrieve_identifiable
(
record
)
for
record
in
to_be_updated
]
self
.
remove_unnecessary_updates
(
to_be_updated
,
identified_records
)
self
.
execute_inserts_in_list
(
to_be_inserted
)
...
...
This diff is collapsed.
Click to expand it.
src/newcrawler/identifiable_adapters.py
+
8
−
18
View file @
be7f26b1
...
...
@@ -148,17 +148,10 @@ class IdentifiableAdapter(object):
# case A: in the registered identifiable
# case B: in the identifiable
if
record
.
get_property
(
prop
.
name
)
is
None
:
raise
NotImplementedError
()
record_prop
=
record
.
get_property
(
prop
.
name
)
newval
=
record_prop
.
value
if
isinstance
(
record_prop
.
value
,
db
.
Entity
):
newval
=
self
.
resolve_reference
(
record_prop
.
value
)
elif
isinstance
(
record_prop
.
value
,
list
):
newval
=
list
()
for
element
in
record_prop
.
value
:
if
isinstance
(
element
,
db
.
Entity
):
newval
.
append
(
self
.
resolve_reference
(
element
))
else
:
newval
.
append
(
element
)
record_prop_new
=
db
.
Property
(
name
=
record_prop
.
name
,
id
=
record_prop
.
id
,
description
=
record_prop
.
description
,
...
...
@@ -287,16 +280,13 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
# a) prop_record.value has a registered identifiable:
# in this case, fetch the identifiable and set the value accordingly
if
isinstance
(
prop
.
value
,
db
.
Entity
):
# lists are not checked here
registered
=
self
.
get_registered_identifiable
(
prop
.
value
)
if
registered
is
None
:
raise
NotImplementedError
(
"
Non-identifiable references cannot
"
"
be used as properties in identifiables.
"
)
raise
RuntimeError
(
"
The identifiable which is used as property
"
"
here has to be inserted first.
"
)
otherid
=
prop_record
.
value
if
isinstance
(
prop_record
.
value
,
db
.
Entity
):
otherid
=
prop_record
.
value
.
id
if
prop
.
value
.
id
!=
otherid
:
return
False
if
prop
.
value
!=
prop_record
.
value
:
el
if
prop
.
value
!=
prop_record
.
value
:
return
False
return
True
...
...
This diff is collapsed.
Click to expand it.
unittests/test_tool.py
+
36
−
20
View file @
be7f26b1
...
...
@@ -18,6 +18,13 @@ import pytest
from
pytest
import
raises
def
basic_ident_lookup
(
rec
,
idents
):
if
rec
.
parents
[
0
].
name
in
idents
:
return
idents
[
rec
.
parents
[
0
].
name
]
else
:
return
None
def
rfp
(
*
pathcomponents
):
"""
Return full path.
...
...
@@ -238,8 +245,15 @@ def test_crawler_update_list(crawler, ident):
assert
len
(
comp
[
0
][
"
properties
"
])
==
0
assert
len
(
comp
[
1
][
"
properties
"
])
==
0
insl
,
updl
=
crawler
.
synchronize
()
insl
,
updl
=
crawler
.
split_into_inserts_and_updates
(
crawler
.
updateList
)
assert
len
(
insl
)
==
0
assert
len
(
updl
)
==
18
identified_records
=
[
crawler
.
identifiableAdapter
.
retrieve_identifiable
(
record
)
for
record
in
updl
]
for
el
in
updl
:
crawler
.
replace_entities_by_ids
(
el
)
Crawler
.
remove_unnecessary_updates
(
updl
,
identified_records
)
assert
len
(
updl
)
==
0
...
...
@@ -430,41 +444,43 @@ def test_split_into_inserts_and_updates_with_copy_attr(mock_retrieve):
def
test_all_references_are_existing_already
(
crawler
):
def
base_mocked_lookup
(
rec
,
known
):
if
rec
.
name
in
known
:
return
known
[
rec
.
name
]
else
:
return
None
registered_identifiables
=
{
"
C
"
:
db
.
Record
().
add_parent
(
"
C
"
).
add_property
(
"
a
"
),
"
D
"
:
db
.
Record
().
add_parent
(
"
D
"
).
add_property
(
"
a
"
).
add_property
(
"
b
"
)}
crawler
.
identifiableAdapter
.
get_registered_identifiable
=
Mock
(
side_effect
=
partial
(
base_mocked_lookup
,
known
=
{
"
A
"
:
db
.
Record
(
name
=
"
A
"
).
add_parent
(
"
C
"
),
"
B
"
:
db
.
Record
(
name
=
"
B
"
).
add_parent
(
"
C
"
)}))
basic_ident_lookup
,
idents
=
registered_identifiables
))
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
().
add_property
(
'
a
'
,
123
))
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
()
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
().
add_parent
(
"
C
"
).
add_property
(
'
a
'
,
123
))
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
().
add_parent
(
"
C
"
)
.
add_property
(
'
a
'
,
db
.
Record
(
id
=
123
)))
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
()
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
()
.
add_parent
(
"
D
"
)
.
add_property
(
'
a
'
,
123
)
.
add_property
(
'
b
'
,
db
.
Record
(
id
=
123
)))
assert
not
crawler
.
all_references_are_existing_already
(
db
.
Record
()
a
=
db
.
Record
(
name
=
"
A
"
).
add_parent
(
"
C
"
).
add_property
(
"
a
"
,
12311
)
assert
not
crawler
.
all_references_are_existing_already
(
db
.
Record
().
add_parent
(
"
D
"
)
.
add_property
(
'
a
'
,
123
)
.
add_property
(
'
b
'
,
db
.
Record
(
name
=
"
A
"
)
.
add_parent
(
"
C
"
)))
a
=
db
.
Record
(
name
=
"
A
"
).
add_parent
(
"
C
"
)
.
add_property
(
'
b
'
,
a
))
crawler
.
add_identified_record_to_local_cache
(
a
)
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
()
assert
crawler
.
all_references_are_existing_already
(
db
.
Record
()
.
add_parent
(
"
D
"
)
.
add_property
(
'
a
'
,
123
)
.
add_property
(
'
b
'
,
a
))
def
test_can_be_checked_externally
(
crawler
):
assert
crawler
.
can_be_checked_externally
(
db
.
Record
().
add_property
(
'
a
'
,
123
))
assert
crawler
.
can_be_checked_externally
(
db
.
Record
()
registered_identifiables
=
{
"
C
"
:
db
.
Record
().
add_parent
(
"
C
"
).
add_property
(
"
a
"
),
"
D
"
:
db
.
Record
().
add_parent
(
"
D
"
).
add_property
(
"
a
"
).
add_property
(
"
b
"
)}
crawler
.
identifiableAdapter
.
get_registered_identifiable
=
Mock
(
side_effect
=
partial
(
basic_ident_lookup
,
idents
=
registered_identifiables
))
assert
crawler
.
can_be_checked_externally
(
db
.
Record
().
add_parent
(
"
C
"
).
add_property
(
'
a
'
,
123
))
assert
crawler
.
can_be_checked_externally
(
db
.
Record
().
add_parent
(
"
C
"
)
.
add_property
(
'
a
'
,
db
.
Record
(
id
=
123
)))
assert
crawler
.
can_be_checked_externally
(
db
.
Record
()
assert
crawler
.
can_be_checked_externally
(
db
.
Record
()
.
add_parent
(
"
D
"
)
.
add_property
(
'
a
'
,
123
)
.
add_property
(
'
b
'
,
db
.
Record
(
id
=
123
)))
assert
not
crawler
.
can_be_checked_externally
(
db
.
Record
()
assert
not
crawler
.
can_be_checked_externally
(
db
.
Record
()
.
add_parent
(
"
D
"
)
.
add_property
(
'
a
'
,
123
)
.
add_property
(
'
b
'
,
db
.
Record
()))
...
...
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