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
968f623f
Commit
968f623f
authored
6 years ago
by
James Johnson
Browse files
Options
Downloads
Patches
Plain Diff
Made recursive key remover more generic
parent
0f06470c
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
+14
-10
14 additions, 10 deletions
force_bdss/io/tests/test_workflow_writer.py
force_bdss/io/workflow_writer.py
+10
-10
10 additions, 10 deletions
force_bdss/io/workflow_writer.py
with
24 additions
and
20 deletions
force_bdss/io/tests/test_workflow_writer.py
+
14
−
10
View file @
968f623f
...
...
@@ -14,7 +14,7 @@ from force_bdss.tests.dummy_classes.factory_registry_plugin import \
DummyFactoryRegistryPlugin
from
force_bdss.io.workflow_writer
import
WorkflowWriter
,
traits_to_dict
,
\
pop_
traits_ve
rsi
on
pop_
recu
rsi
ve
from
force_bdss.core.workflow
import
Workflow
...
...
@@ -89,13 +89,17 @@ class TestWorkflowWriter(unittest.TestCase):
self
.
assertEqual
(
traits_to_dict
(
mock_traits
),
{
"
foo
"
:
"
bar
"
})
def
test_pop_
traits_ve
rsi
on
(
self
):
def
test_pop_
recu
rsi
ve
(
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_version
(
test_dictionary
)
self
.
assertEqual
(
traitless_dictionary
,
result_dictionary
)
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
,
)
self
.
assertEqual
(
test_result_dictionary
,
result_dictionary
)
This diff is collapsed.
Click to expand it.
force_bdss/io/workflow_writer.py
+
10
−
10
View file @
968f623f
...
...
@@ -95,28 +95,28 @@ def traits_to_dict(traits_obj):
state
=
traits_obj
.
__getstate__
()
state
=
pop_traits_version
(
state
)
state
=
pop_
recursive
(
state
,
'
__
traits_version
__
'
)
return
state
def
pop_
traits_ve
rsi
on
(
dictionary
):
"""
Recursively remove
the __traits_version__ attribute
from
dictionar
y
.
"""
def
pop_
recu
rsi
ve
(
dictionary
,
remove_key
):
"""
Recursively remove
a named key from dictionary and any contained
dictionar
ies
.
"""
try
:
dictionary
.
pop
(
"
__traits_version__
"
)
dictionary
.
pop
(
remove_key
)
except
KeyError
:
pass
for
key
in
dictionary
:
# If
we have a dict, remove the traits version
# If
remove_key is in the dict, remove it
if
isinstance
(
dictionary
[
key
],
dict
):
pop_
traits_ve
rsi
on
(
dictionary
[
key
])
# If we have a non-dict which contains a dict,
remove traits from
# that as well
pop_
recu
rsi
ve
(
dictionary
[
key
]
,
remove_key
)
# If we have a non-dict
iterable
which contains a dict,
#
call pop.(remove_key) from
that as well
elif
isinstance
(
dictionary
[
key
],
Iterable
):
for
element
in
dictionary
[
key
]:
if
isinstance
(
element
,
dict
):
pop_
traits_ve
rsi
on
(
element
)
pop_
recu
rsi
ve
(
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