Skip to content
Snippets Groups Projects
Commit 653dc393 authored by James Johnson's avatar James Johnson
Browse files

updated key-value pairs, added tests which call traits_to_dict

parent 7f4ba93b
No related branches found
No related tags found
1 merge request!152Removed __traits_version__ from json files
......@@ -16,6 +16,7 @@ from force_bdss.tests.dummy_classes.factory_registry_plugin import \
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):
......@@ -89,7 +90,18 @@ class TestWorkflowWriter(unittest.TestCase):
self.assertEqual(traits_to_dict(mock_traits), {"foo": "bar"})
def test_pop_recursive(self):
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',
......
......@@ -108,14 +108,14 @@ def pop_recursive(dictionary, remove_key):
except KeyError:
pass
for key in dictionary:
for key,value in dictionary.items():
# If remove_key is in the dict, remove it
if isinstance(dictionary[key], dict):
pop_recursive(dictionary[key], remove_key)
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(dictionary[key], Iterable):
for element in dictionary[key]:
elif isinstance(value, (tuple, list)):
for element in value:
if isinstance(element, dict):
pop_recursive(element, remove_key)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment