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
28b1b816
Commit
28b1b816
authored
11 months ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
DOC: docstring
parent
2e354a0c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!178
FIX: #96 Better error output for crawl.py script.
,
!167
Sync Graph
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/identifiable_adapters.py
+8
-0
8 additions, 0 deletions
src/caoscrawler/identifiable_adapters.py
unittests/test_file_identifiables.py
+0
-70
0 additions, 70 deletions
unittests/test_file_identifiables.py
with
8 additions
and
70 deletions
src/caoscrawler/identifiable_adapters.py
+
8
−
0
View file @
28b1b816
...
...
@@ -149,6 +149,14 @@ identifiabel, identifiable and identified record) for a Record.
return
query_string
def
check_identifying_props
(
self
,
node
,
raise_exception
=
True
):
"""
checks whether all identifying properties exist and raises an error if not
If raise_exception is False, the function returns False instead of raising an error.
Backreferences are not checked.
Returns True if all identifying properties exist.
"""
if
node
.
registered_identifiable
is
None
:
if
raise_exception
:
raise
RuntimeError
(
"
no registered_identifiable
"
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_file_identifiables.py
deleted
100644 → 0
+
0
−
70
View file @
2e354a0c
#!/bin/python
# Tests for file identifiables
# A. Schlemmer, 06/2021
from
unittest.mock
import
Mock
,
patch
import
caosdb
as
db
import
pytest
from
caoscrawler.identifiable
import
Identifiable
from
caoscrawler.identifiable_adapters
import
LocalStorageIdentifiableAdapter
from
caoscrawler.sync_graph
import
SyncNode
from
caosdb.cached
import
cache_clear
from
caosdb.exceptions
import
EmptyUniqueQueryError
from
pytest
import
raises
from
test_crawler
import
mock_get_entity_by
@pytest.fixture
(
autouse
=
True
)
def
clear_cache
():
cache_clear
()
@patch
(
"
caoscrawler.identifiable_adapters.get_children_of_rt
"
,
new
=
Mock
(
side_effect
=
id
))
@patch
(
"
caoscrawler.identifiable_adapters.cached_get_entity_by
"
,
new
=
Mock
(
side_effect
=
mock_get_entity_by
))
def
test_file_identifiable
():
ident
=
LocalStorageIdentifiableAdapter
()
# Without a path there is no identifying information
with
raises
(
ValueError
):
ident
.
get_identifiable
(
SyncNode
(
db
.
File
(),
None
),
[])
fp
=
"
/test/bla/bla.txt
"
file_obj
=
db
.
File
(
path
=
fp
)
identifiable
=
ident
.
get_identifiable
(
SyncNode
(
file_obj
,
None
),
[])
# the path is copied to the identifiable
assert
fp
==
identifiable
.
path
assert
isinstance
(
identifiable
,
Identifiable
)
# __eq__ function is only defined for Identifiable objects
with
raises
(
ValueError
):
file_obj
!=
identifiable
# since the path does not exist in the data in ident, the follwoing functions return None
with
raises
(
EmptyUniqueQueryError
):
ident
.
retrieve_identified_record_for_record
(
file_obj
)
assert
ident
.
get_file
(
identifiable
)
is
None
# Try again with actual files in the store:
records
=
ident
.
get_records
()
test_record_wrong_path
=
db
.
File
(
path
=
"
/bla/bla/test.txt
"
)
test_record_correct_path
=
db
.
File
(
path
=
"
/test/bla/bla.txt
"
)
test_record_alsocorrect_path
=
db
.
File
(
path
=
"
/test/bla/bla.txt
"
)
records
.
append
(
test_record_wrong_path
)
# Now, there is a file, but still wrong path -> result is still None
identified_file
=
ident
.
get_file
(
file_obj
)
assert
identified_file
is
None
records
.
append
(
test_record_correct_path
)
# now there is a match
identified_file
=
ident
.
get_file
(
file_obj
)
assert
identified_file
is
not
None
assert
identified_file
.
path
==
file_obj
.
path
with
raises
(
RuntimeError
,
match
=
"
.*unambigiously.*
"
):
records
.
append
(
test_record_alsocorrect_path
)
identified_file
=
ident
.
get_file
(
file_obj
)
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