Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
force-bdss
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
Service Desk
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
Adham Hashibon
force-bdss
Commits
d48e06bd
Commit
d48e06bd
authored
6 years ago
by
Stefano Borini
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 49-base-class-for-factory
parents
013f21f9
61b6a8f8
No related branches found
No related tags found
1 merge request
!158
Introduces base class and interface for the factories
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
force_bdss/api.py
+13
-0
13 additions, 0 deletions
force_bdss/api.py
force_bdss/io/tests/test_workflow_writer.py
+29
-1
29 additions, 1 deletion
force_bdss/io/tests/test_workflow_writer.py
force_bdss/io/workflow_writer.py
+23
-2
23 additions, 2 deletions
force_bdss/io/workflow_writer.py
with
65 additions
and
3 deletions
force_bdss/api.py
+
13
−
0
View file @
d48e06bd
...
...
@@ -5,12 +5,25 @@ from .core.data_value import DataValue # noqa
from
.core.workflow
import
Workflow
# noqa
from
.core.slot
import
Slot
# noqa
from
.core.i_factory
import
IFactory
# noqa
from
.core.input_slot_info
import
InputSlotInfo
# noqa
from
.core.output_slot_info
import
OutputSlotInfo
# noqa
from
.core.kpi_specification
import
KPISpecification
# noqa
from
.core.execution_layer
import
ExecutionLayer
# noqa
from
.core.verifier
import
verify_workflow
# noqa
from
.core.verifier
import
VerifierError
# noqa
from
.data_sources.base_data_source_model
import
BaseDataSourceModel
# noqa
from
.data_sources.base_data_source
import
BaseDataSource
# noqa
from
.data_sources.base_data_source_factory
import
BaseDataSourceFactory
# noqa
from
.data_sources.i_data_source_factory
import
IDataSourceFactory
# noqa
from
.factory_registry_plugin
import
IFactoryRegistryPlugin
# noqa
from
.factory_registry_plugin
import
FactoryRegistryPlugin
# noqa
from
.io.workflow_reader
import
WorkflowReader
# noqa
from
.io.workflow_reader
import
InvalidFileException
# noqa
from
.io.workflow_writer
import
WorkflowWriter
# noqa
from
.mco.base_mco_model
import
BaseMCOModel
# noqa
from
.mco.base_mco_communicator
import
BaseMCOCommunicator
# noqa
from
.mco.base_mco
import
BaseMCO
# noqa
...
...
This diff is collapsed.
Click to expand it.
force_bdss/io/tests/test_workflow_writer.py
+
29
−
1
View file @
d48e06bd
...
...
@@ -13,8 +13,10 @@ from force_bdss.io.workflow_reader import WorkflowReader
from
force_bdss.tests.dummy_classes.factory_registry_plugin
import
\
DummyFactoryRegistryPlugin
from
force_bdss.io.workflow_writer
import
WorkflowWriter
,
traits_to_dict
from
force_bdss.io.workflow_writer
import
WorkflowWriter
,
traits_to_dict
,
\
pop_recursive
from
force_bdss.core.workflow
import
Workflow
from
force_bdss.core.input_slot_info
import
InputSlotInfo
class
TestWorkflowWriter
(
unittest
.
TestCase
):
...
...
@@ -87,3 +89,29 @@ class TestWorkflowWriter(unittest.TestCase):
mock_traits
.
__getstate__
=
mock
.
Mock
(
return_value
=
{
"
foo
"
:
"
bar
"
})
self
.
assertEqual
(
traits_to_dict
(
mock_traits
),
{
"
foo
"
:
"
bar
"
})
def
test_traits_to_dict
(
self
):
wfwriter
=
WorkflowWriter
()
wf
=
self
.
_create_workflow
()
exec_layer
=
wf
.
execution_layers
[
0
]
exec_layer
.
data_sources
[
0
].
input_slot_info
=
[
InputSlotInfo
()]
slotdata
=
exec_layer
.
data_sources
[
0
].
input_slot_info
[
0
].
__getstate__
()
self
.
assertTrue
(
"
__traits_version__
"
in
slotdata
)
# Calls traits_to_dict for each data source
datastore_list
=
wfwriter
.
_execution_layer_data
(
exec_layer
)
new_slotdata
=
datastore_list
[
0
][
'
model_data
'
][
'
input_slot_info
'
]
self
.
assertTrue
(
"
__traits_version__
"
not
in
new_slotdata
)
test_dictionary
=
{
'
K1
'
:
{
'
K1
'
:
'
V1
'
,
'
K2
'
:
'
V2
'
,
'
K3
'
:
'
V3
'
},
'
K2
'
:
[
'
V1
'
,
'
V2
'
,
{
'
K1
'
:
'
V1
'
,
'
K2
'
:
'
V2
'
,
'
K3
'
:
'
V3
'
}],
'
K3
'
:
'
V3
'
,
'
K4
'
:
(
'
V1
'
,
{
'
K3
'
:
'
V3
'
},)}
result_dictionary
=
{
'
K1
'
:
{
'
K1
'
:
'
V1
'
,
'
K2
'
:
'
V2
'
,
},
'
K2
'
:
[
'
V1
'
,
'
V2
'
,
{
'
K1
'
:
'
V1
'
,
'
K2
'
:
'
V2
'
,
}],
'
K4
'
:
(
'
V1
'
,
{},)}
test_result_dictionary
=
pop_recursive
(
test_dictionary
,
'
K3
'
)
self
.
assertEqual
(
test_result_dictionary
,
result_dictionary
)
This diff is collapsed.
Click to expand it.
force_bdss/io/workflow_writer.py
+
23
−
2
View file @
d48e06bd
...
...
@@ -91,10 +91,31 @@ class WorkflowWriter(HasStrictTraits):
def
traits_to_dict
(
traits_obj
):
"""
Converts a traits class into a dict, removing the pesky
traits version.
"""
state
=
traits_obj
.
__getstate__
()
state
=
pop_recursive
(
state
,
'
__traits_version__
'
)
return
state
def
pop_recursive
(
dictionary
,
remove_key
):
"""
Recursively remove a named key from dictionary and any contained
dictionaries.
"""
try
:
state
.
pop
(
"
__traits_version__
"
)
dictionary
.
pop
(
remove_key
)
except
KeyError
:
pass
return
state
for
key
,
value
in
dictionary
.
items
():
# If remove_key is in the dict, remove it
if
isinstance
(
value
,
dict
):
pop_recursive
(
value
,
remove_key
)
# If we have a non-dict iterable which contains a dict,
# call pop.(remove_key) from that as well
elif
isinstance
(
value
,
(
tuple
,
list
)):
for
element
in
value
:
if
isinstance
(
element
,
dict
):
pop_recursive
(
element
,
remove_key
)
return
dictionary
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