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
dd052776
Unverified
Commit
dd052776
authored
6 years ago
by
jjenthought
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #152 from force-h2020/163-save-load-behaviour-bdss
Merged #152
parents
dc2dbce4
e9053ef7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
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
52 additions
and
3 deletions
force_bdss/io/tests/test_workflow_writer.py
+
29
−
1
View file @
dd052776
...
@@ -13,8 +13,10 @@ from force_bdss.io.workflow_reader import WorkflowReader
...
@@ -13,8 +13,10 @@ from force_bdss.io.workflow_reader import WorkflowReader
from
force_bdss.tests.dummy_classes.factory_registry_plugin
import
\
from
force_bdss.tests.dummy_classes.factory_registry_plugin
import
\
DummyFactoryRegistryPlugin
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.workflow
import
Workflow
from
force_bdss.core.input_slot_info
import
InputSlotInfo
class
TestWorkflowWriter
(
unittest
.
TestCase
):
class
TestWorkflowWriter
(
unittest
.
TestCase
):
...
@@ -87,3 +89,29 @@ class TestWorkflowWriter(unittest.TestCase):
...
@@ -87,3 +89,29 @@ class TestWorkflowWriter(unittest.TestCase):
mock_traits
.
__getstate__
=
mock
.
Mock
(
return_value
=
{
"
foo
"
:
"
bar
"
})
mock_traits
.
__getstate__
=
mock
.
Mock
(
return_value
=
{
"
foo
"
:
"
bar
"
})
self
.
assertEqual
(
traits_to_dict
(
mock_traits
),
{
"
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 @
dd052776
...
@@ -91,10 +91,31 @@ class WorkflowWriter(HasStrictTraits):
...
@@ -91,10 +91,31 @@ class WorkflowWriter(HasStrictTraits):
def
traits_to_dict
(
traits_obj
):
def
traits_to_dict
(
traits_obj
):
"""
Converts a traits class into a dict, removing the pesky
"""
Converts a traits class into a dict, removing the pesky
traits version.
"""
traits version.
"""
state
=
traits_obj
.
__getstate__
()
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
:
try
:
state
.
pop
(
"
__traits_version__
"
)
dictionary
.
pop
(
remove_key
)
except
KeyError
:
except
KeyError
:
pass
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