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
f2a24be0
Commit
f2a24be0
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: added unit test for file identifiables
parent
a9cfd002
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
+6
-1
6 additions, 1 deletion
src/newcrawler/identifiable_adapters.py
unittests/test_file_identifiables.py
+47
-0
47 additions, 0 deletions
unittests/test_file_identifiables.py
with
53 additions
and
1 deletion
src/newcrawler/identifiable_adapters.py
+
6
−
1
View file @
f2a24be0
...
...
@@ -214,6 +214,8 @@ class IdentifiableAdapter(metaclass=ABCMeta):
This function will return None if there is either no identifiable registered
or no corresponding identified record in the database for a given record.
Warning: this function is not expected to work correctly for file identifiables.
"""
pass
...
...
@@ -253,6 +255,9 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
def
get_records
(
self
):
return
self
.
_records
def
get_file
(
self
,
identifiable
:
db
.
File
):
raise
NotImplementedError
()
def
store_state
(
self
,
filename
):
with
open
(
filename
,
"
w
"
)
as
f
:
f
.
write
(
db
.
common
.
utils
.
xml2str
(
db
.
Container
().
extend
(
self
.
_records
).
to_xml
()))
...
...
@@ -331,7 +336,7 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return
False
return
True
def
retrieve_identified_record
(
self
,
identifiable
:
db
.
Record
):
def
retrieve_identified_record
_for_identifiable
(
self
,
identifiable
:
db
.
Record
):
candidates
=
[]
for
record
in
self
.
_records
:
if
self
.
check_record
(
record
,
identifiable
):
...
...
This diff is collapsed.
Click to expand it.
unittests/test_file_identifiables.py
0 → 100644
+
47
−
0
View file @
f2a24be0
#!/bin/python
# Tests for file identifiables
# A. Schlemmer, 06/2021
import
caosdb
as
db
import
pytest
from
pytest
import
raises
from
newcrawler.identifiable_adapters
import
LocalStorageIdentifiableAdapter
def
test_file_identifiable
():
ident
=
LocalStorageIdentifiableAdapter
()
file_obj
=
db
.
File
()
identifiable
=
ident
.
get_identifiable
(
file_obj
)
identifiable2
=
ident
.
get_identifiable_for_file
(
file_obj
)
# these are two different objects:
assert
identifiable
!=
identifiable2
assert
file_obj
!=
identifiable
# ... but the path is equal:
assert
identifiable
.
path
==
identifiable2
.
path
# ... and very boring:
assert
identifiable
.
path
is
None
# TODO: test for corresponding retrieval "get_file"
# Let's make it more interesting:
file_obj
.
path
=
"
/test/bla/bla.txt
"
file_obj
.
_checksum
=
"
abcd
"
identifiable
=
ident
.
get_identifiable
(
file_obj
)
assert
file_obj
!=
identifiable
assert
file_obj
.
path
==
identifiable
.
path
# Checksum is not part of the identifiable:
assert
file_obj
.
checksum
!=
identifiable
.
checksum
# This is the wrong method, so it should definitely return None:
identified_file
=
ident
.
retrieve_identified_record_for_identifiable
(
identifiable
)
assert
identified_file
is
None
# This is the correct method to use:
identified_file
=
ident
.
get_file
(
identifiable
)
# or directly using:
identified_file2
=
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