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
b3ae9bc1
Commit
b3ae9bc1
authored
Feb 1, 2022
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: extended test for getting file identifiables
parent
f2a24be0
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
+12
-1
12 additions, 1 deletion
src/newcrawler/identifiable_adapters.py
unittests/test_file_identifiables.py
+30
-2
30 additions, 2 deletions
unittests/test_file_identifiables.py
with
42 additions
and
3 deletions
src/newcrawler/identifiable_adapters.py
+
12
−
1
View file @
b3ae9bc1
...
@@ -256,7 +256,18 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
...
@@ -256,7 +256,18 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return
self
.
_records
return
self
.
_records
def
get_file
(
self
,
identifiable
:
db
.
File
):
def
get_file
(
self
,
identifiable
:
db
.
File
):
raise
NotImplementedError
()
"""
Just look in records for a file with the same path.
"""
candidates
=
[]
for
record
in
self
.
_records
:
if
record
.
role
==
"
File
"
and
record
.
path
==
identifiable
.
path
:
candidates
.
append
(
record
)
if
len
(
candidates
)
>
1
:
raise
RuntimeError
(
"
Identifiable was not defined unambigiously.
"
)
if
len
(
candidates
)
==
0
:
return
None
return
candidates
[
0
]
def
store_state
(
self
,
filename
):
def
store_state
(
self
,
filename
):
with
open
(
filename
,
"
w
"
)
as
f
:
with
open
(
filename
,
"
w
"
)
as
f
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_file_identifiables.py
+
30
−
2
View file @
b3ae9bc1
...
@@ -24,8 +24,12 @@ def test_file_identifiable():
...
@@ -24,8 +24,12 @@ def test_file_identifiable():
assert
identifiable
.
path
==
identifiable2
.
path
assert
identifiable
.
path
==
identifiable2
.
path
# ... and very boring:
# ... and very boring:
assert
identifiable
.
path
is
None
assert
identifiable
.
path
is
None
# Test functionality of retrieving the files:
# TODO: test for corresponding retrieval "get_file"
identified_file
=
ident
.
get_file
(
identifiable
)
identified_file2
=
ident
.
get_file
(
file_obj
)
# The both should be None currently as there are no files in the local store yet:
assert
identified_file
is
None
assert
identified_file2
is
None
# Let's make it more interesting:
# Let's make it more interesting:
file_obj
.
path
=
"
/test/bla/bla.txt
"
file_obj
.
path
=
"
/test/bla/bla.txt
"
...
@@ -43,5 +47,29 @@ def test_file_identifiable():
...
@@ -43,5 +47,29 @@ def test_file_identifiable():
identified_file
=
ident
.
get_file
(
identifiable
)
identified_file
=
ident
.
get_file
(
identifiable
)
# or directly using:
# or directly using:
identified_file2
=
ident
.
get_file
(
file_obj
)
identified_file2
=
ident
.
get_file
(
file_obj
)
# The both should be None currently as there are no files in the local store yet:
assert
identified_file
is
None
assert
identified_file2
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
)
identified_file
=
ident
.
get_file
(
file_obj
)
assert
identified_file
is
None
records
.
append
(
test_record_correct_path
)
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