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
e1454c4d
Commit
e1454c4d
authored
6 years ago
by
James Johnson
Browse files
Options
Downloads
Patches
Plain Diff
Added test of pop_traits_version
parent
cf12878b
No related branches found
No related tags found
1 merge request
!152
Removed __traits_version__ from json files
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
force_bdss/io/tests/test_workflow_writer.py
+13
-1
13 additions, 1 deletion
force_bdss/io/tests/test_workflow_writer.py
force_bdss/io/workflow_writer.py
+23
-22
23 additions, 22 deletions
force_bdss/io/workflow_writer.py
with
36 additions
and
23 deletions
force_bdss/io/tests/test_workflow_writer.py
+
13
−
1
View file @
e1454c4d
...
...
@@ -13,7 +13,8 @@ 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_traits
from
force_bdss.core.workflow
import
Workflow
...
...
@@ -87,3 +88,14 @@ class TestWorkflowWriter(unittest.TestCase):
mock_traits
.
__getstate__
=
mock
.
Mock
(
return_value
=
{
"
foo
"
:
"
bar
"
})
self
.
assertEqual
(
traits_to_dict
(
mock_traits
),
{
"
foo
"
:
"
bar
"
})
def
test_pop_traits_version
(
self
):
test_dictionary
=
{
'
Entry1
'
:
{
'
Entry1-1
'
:
4
,
'
__traits_version__
'
:
67
},
'
Entry2
'
:
[
3
,
'
a
'
,
{
'
Entry2-1
'
:
5
,
'
__traits_version__
'
:
9001
}],
'
__traits_version__
'
:
13
}
result_dictionary
=
{
'
Entry1
'
:
{
'
Entry1-1
'
:
4
,
},
'
Entry2
'
:
[
3
,
'
a
'
,
{
'
Entry2-1
'
:
5
,
}],
}
traitless_dictionary
=
pop_traits
(
test_dictionary
)
self
.
assertEqual
(
traitless_dictionary
,
result_dictionary
)
This diff is collapsed.
Click to expand it.
force_bdss/io/workflow_writer.py
+
23
−
22
View file @
e1454c4d
...
...
@@ -93,29 +93,30 @@ def traits_to_dict(traits_obj):
"""
Converts a traits class into a dict, removing the pesky
traits version.
"""
def
pop_traits
(
dictionary
):
"""
Recursively remove the __traits_version__ attribute
from dictionary.
"""
try
:
dictionary
.
pop
(
"
__traits_version__
"
)
except
KeyError
:
pass
for
key
in
dictionary
:
# If we have a dict, remove the traits version
if
isinstance
(
dictionary
[
key
],
dict
):
pop_traits
(
dictionary
[
key
])
# If we have a non-dict which contains a dict, remove traits from
# that as well
elif
isinstance
(
dictionary
[
key
],
Iterable
):
for
element
in
dictionary
[
key
]:
if
isinstance
(
element
,
dict
):
pop_traits
(
element
)
return
dictionary
state
=
traits_obj
.
__getstate__
()
state
=
pop_traits
(
state
)
state
=
pop_traits
_version
(
state
)
return
state
def
pop_traits_version
(
dictionary
):
"""
Recursively remove the __traits_version__ attribute
from dictionary.
"""
try
:
dictionary
.
pop
(
"
__traits_version__
"
)
except
KeyError
:
pass
for
key
in
dictionary
:
# If we have a dict, remove the traits version
if
isinstance
(
dictionary
[
key
],
dict
):
pop_traits
(
dictionary
[
key
])
# If we have a non-dict which contains a dict, remove traits from
# that as well
elif
isinstance
(
dictionary
[
key
],
Iterable
):
for
element
in
dictionary
[
key
]:
if
isinstance
(
element
,
dict
):
pop_traits
(
element
)
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