def test_data_mapping_select(self): """ Key/value mapping overwrites can be limited by selecting data first """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = { 'data_mapping': { 'dummy': 'param1', 'param1': 'dummy' }, 'data_select': ['param1'] } self.assertDictEqual(edge_select_transform(data, edge), {'dummy': True}) edge = { 'data_mapping': { 'dummy': 'param1', 'param1': 'dummy' }, 'data_select': ['dummy'] } self.assertDictEqual(edge_select_transform(data, edge), {'param1': 12})
def test_data_select(self): """ Only select 'dummy' attribute """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {'data_select': ['dummy']} self.assertDictEqual(edge_select_transform(data, edge), {'dummy': 12})
def test_default(self): """ No select/mapping directives in edge, all data returned """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {} self.assertDictEqual(edge_select_transform(data, edge), data)
def test_data_select_nested_two(self): """ Identically named (nested) parameters are handled in alphabetic order """ data = {'dummy': 12, 'param1': True, 'param2': {'dummy': 5}} edge = {'data_select': ['param2.dummy', 'dummy']} self.assertDictEqual(edge_select_transform(data, edge), {'dummy': 12})
def test_data_select_nested(self): """ Collect single key/value pairs in nested data sets """ data = {'dummy': 12, 'param1': True, 'param2': {'dummy': 5}} edge = {'data_select': ['param2.dummy']} self.assertDictEqual(edge_select_transform(data, edge), {'dummy': 5})
def test_data_select_undefined(self): """ When data is not available log a warning but continue as the parameter may be optional. """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {'data_select': ['dummy', 'param4']} self.assertDictEqual(edge_select_transform(data, edge), {'dummy': 12})
def test_data_mapping_three(self): """ Return all data but translate two parameters """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {'data_mapping': {'param1': 'bar1', 'param2': 'bar2'}} self.assertDictEqual(edge_select_transform(data, edge), { 'dummy': 12, 'bar1': True, 'bar2': [1, 2, 3], 'param3': 5 })
def test_data_mapping_two(self): """ Return all data but translate 'param3' to 'dummy'. Results in dummy parameter being overwritten by param3 value """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {'data_mapping': {'param3': 'dummy'}} self.assertDictEqual(edge_select_transform(data, edge), { 'dummy': 5, 'param1': True, 'param2': [1, 2, 3] })
def test_data_mapping(self): """ Return all data but translate 'dummy' to 'bar' """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {'data_mapping': {'dummy': 'bar'}} self.assertDictEqual(edge_select_transform(data, edge), { 'bar': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5 })
def test_data_mapping_four(self): """ Mapping may result in key/value pairs being overwritten. Parameter renaming is handled in alphabetic order. """ data = {'dummy': 12, 'param1': True, 'param2': [1, 2, 3], 'param3': 5} edge = {'data_mapping': {'dummy': 'param1', 'param1': 'dummy'}} self.assertDictEqual(edge_select_transform(data, edge), { 'param1': 12, 'dummy': True, 'param2': [1, 2, 3], 'param3': 5 })
def test_data_select_nested_three(self): """ Select and rename nested parameters """ data = {'dummy': 12, 'param1': True, 'param2': {'dummy': 5}} edge = { 'data_select': ['param2.dummy', 'dummy'], 'data_mapping': { 'param2.dummy': 'bar' } } self.assertDictEqual(edge_select_transform(data, edge), { 'bar': 5, 'dummy': 12 })