Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
esde
machine-learning
MLAir
Commits
d48d8b47
Commit
d48d8b47
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
added method search_scope
parent
b350d93e
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!17
update to v0.4.0
,
!14
include data storage
Pipeline
#26370
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/datastore.py
+74
-3
74 additions, 3 deletions
src/datastore.py
test/test_datastore.py
+54
-1
54 additions, 1 deletion
test/test_datastore.py
with
128 additions
and
4 deletions
src/datastore.py
+
74
−
3
View file @
d48d8b47
...
...
@@ -20,6 +20,13 @@ class NameNotFoundInScope(Exception):
pass
class
EmptyScope
(
Exception
):
"""
Exception that get raised if given scope is not part of the data store.
"""
pass
class
AbstractDataStore
(
ABC
):
"""
...
...
@@ -57,6 +64,21 @@ class AbstractDataStore(ABC):
"""
pass
def
search_scope
(
self
,
scope
:
str
)
->
None
:
"""
Abstract method to search for all object names that are stored for given scope
:param scope: scope to look for
:return: search result
"""
pass
def
list_all_scopes
(
self
)
->
None
:
"""
Abstract method to list all scopes in data store
:return: all found scopes
"""
pass
class
DataStoreByVariable
(
AbstractDataStore
):
...
...
@@ -106,10 +128,11 @@ class DataStoreByVariable(AbstractDataStore):
except
KeyError
:
return
self
.
get
(
name
,
scope
.
rsplit
(
"
.
"
,
maxsplit
=
depth
)[
0
],
depth
-
1
)
else
:
if
name
in
self
.
_store
.
keys
():
try
:
occurrences
=
self
.
search_name
(
name
)
raise
NameNotFoundInScope
(
f
"
Couldn
'
t find
{
name
}
in scope
{
scope
}
.
{
name
}
is only defined in
"
f
"
{
self
.
search_name
(
name
)
}
"
)
e
lse
:
f
"
{
occurrences
}
"
)
e
xcept
KeyError
:
raise
NameNotFoundInDataStore
(
f
"
Couldn
'
t find
{
name
}
in data store
"
)
def
search_name
(
self
,
name
:
str
)
->
List
[
str
]:
...
...
@@ -120,6 +143,34 @@ class DataStoreByVariable(AbstractDataStore):
"""
return
sorted
(
self
.
_store
[
name
])
def
search_scope
(
self
,
scope
:
str
)
->
List
[
str
]:
"""
Search for given `scope` and list all object names stored under this scope.
:param scope: scope to look for
:return: list with all object names
"""
names
=
[]
for
(
k
,
v
)
in
self
.
_store
.
items
():
if
scope
in
v
.
keys
():
names
.
append
(
k
)
if
len
(
names
)
>
0
:
return
sorted
(
names
)
else
:
raise
EmptyScope
(
f
"
Given scope
{
scope
}
is not part of the data store. Available scopes are:
"
f
"
{
self
.
list_all_scopes
()
}
"
)
def
list_all_scopes
(
self
)
->
List
[
str
]:
"""
List all available scopes in data store
:return: names of all stored objects
"""
scopes
=
[]
for
v
in
self
.
_store
.
values
():
for
scope
in
v
.
keys
():
if
scope
not
in
scopes
:
scopes
.
append
(
scope
)
return
sorted
(
scopes
)
class
DataStoreByScope
(
AbstractDataStore
):
...
...
@@ -175,6 +226,8 @@ class DataStoreByScope(AbstractDataStore):
raise
NameNotFoundInScope
(
f
"
Couldn
'
t find
{
name
}
in scope
{
scope
}
.
{
name
}
is only defined in
"
f
"
{
occurrences
}
"
)
def
search_name
(
self
,
name
:
str
)
->
List
[
str
]:
"""
Search for all occurrences of given `name` in the entire data store.
...
...
@@ -187,4 +240,22 @@ class DataStoreByScope(AbstractDataStore):
keys
.
append
(
key
)
return
sorted
(
keys
)
def
search_scope
(
self
,
scope
:
str
,
current_scope_only
=
True
)
->
List
[
str
]:
"""
Search for given `scope` and list all object names stored under this scope.
:param scope: scope to look for
:return: list with all object names
"""
try
:
return
sorted
(
self
.
_store
[
scope
].
keys
())
except
KeyError
:
raise
EmptyScope
(
f
"
Given scope
{
scope
}
is not part of the data store. Available scopes are:
"
f
"
{
self
.
list_all_scopes
()
}
"
)
def
list_all_scopes
(
self
)
->
List
[
str
]:
"""
List all available scopes in data store
:return: names of all stored objects
"""
return
sorted
(
self
.
_store
.
keys
())
This diff is collapsed.
Click to expand it.
test/test_datastore.py
+
54
−
1
View file @
d48d8b47
...
...
@@ -3,7 +3,7 @@ __date__ = '2019-11-22'
from
src.datastore
import
AbstractDataStore
,
DataStoreByVariable
,
DataStoreByScope
from
src.datastore
import
NameNotFoundInDataStore
,
NameNotFoundInScope
from
src.datastore
import
NameNotFoundInDataStore
,
NameNotFoundInScope
,
EmptyScope
import
pytest
...
...
@@ -61,6 +61,28 @@ class TestDataStoreByVariable:
ds
.
get
(
"
number
"
,
"
general
"
)
assert
"
Couldn
'
t find number in scope general. number is only defined in [
'
general.sub
'
]
"
in
e
.
value
.
args
[
0
]
def
test_list_all_scopes
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general2
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
ds
.
put
(
"
number
"
,
3
,
"
general.sub3
"
)
ds
.
put
(
"
number
"
,
1
,
"
general
"
)
assert
ds
.
list_all_scopes
()
==
[
'
general
'
,
'
general.sub
'
,
'
general.sub3
'
,
'
general2
'
]
def
test_search_scope
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
ds
.
put
(
"
number1
"
,
22
,
"
general.sub
"
)
ds
.
put
(
"
number2
"
,
3
,
"
general.sub.sub
"
)
assert
ds
.
search_scope
(
"
general.sub
"
)
==
[
"
number
"
,
"
number1
"
]
def
test_search_empty_scope
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general2
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
with
pytest
.
raises
(
EmptyScope
)
as
e
:
ds
.
search_scope
(
"
general.sub2
"
)
assert
"
Given scope general.sub2 is not part of the data store.
"
in
e
.
value
.
args
[
0
]
assert
"
Available scopes are: [
'
general.sub
'
,
'
general2
'
]
"
in
e
.
value
.
args
[
0
]
class
TestDataStoreByScope
:
...
...
@@ -105,3 +127,34 @@ class TestDataStoreByScope:
with
pytest
.
raises
(
NameNotFoundInScope
)
as
e
:
ds
.
get
(
"
number
"
,
"
general
"
)
assert
"
Couldn
'
t find number in scope general. number is only defined in [
'
general.sub
'
]
"
in
e
.
value
.
args
[
0
]
def
test_list_all_scopes
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general2
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
ds
.
put
(
"
number
"
,
3
,
"
general.sub3
"
)
ds
.
put
(
"
number
"
,
1
,
"
general
"
)
assert
ds
.
list_all_scopes
()
==
[
'
general
'
,
'
general.sub
'
,
'
general.sub3
'
,
'
general2
'
]
def
test_search_scope
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
ds
.
put
(
"
number1
"
,
22
,
"
general.sub
"
)
ds
.
put
(
"
number2
"
,
3
,
"
general.sub.sub
"
)
assert
ds
.
search_scope
(
"
general.sub
"
)
==
[
"
number
"
,
"
number1
"
]
def
test_search_empty_scope
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general2
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
with
pytest
.
raises
(
EmptyScope
)
as
e
:
ds
.
search_scope
(
"
general.sub2
"
)
assert
"
Given scope general.sub2 is not part of the data store.
"
in
e
.
value
.
args
[
0
]
assert
"
Available scopes are: [
'
general.sub
'
,
'
general2
'
]
"
in
e
.
value
.
args
[
0
]
def
test_search_scope_and_all_superiors
(
self
,
ds
):
ds
.
put
(
"
number
"
,
22
,
"
general
"
)
ds
.
put
(
"
number
"
,
11
,
"
general.sub
"
)
ds
.
put
(
"
number1
"
,
22
,
"
general.sub
"
)
ds
.
put
(
"
number2
"
,
3
,
"
general.sub.sub
"
)
assert
ds
.
search_scope
(
"
general.sub
"
,
current_scope_only
=
False
)
==
[
"
number
"
,
"
number1
"
]
assert
ds
.
search_scope
(
"
general.sub.sub
"
,
current_scope_only
=
False
)
==
[
"
number
"
,
"
number1
"
,
"
number2
"
]
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