예제 #1
0
 def test_replace_value_replaces_existing_value_in_doubly_cascaded_dict(
         self):
     target_dict = {'kfoo': {'kfoobar': {'kbar': 'vfoo'}}}
     replacement = {'vfoo': 'vbar'}
     target_dict = utils.replace_value_in_dict(replacement, target_dict)
     self.assertEqual(replacement['vfoo'],
                      target_dict['kfoo']['kfoobar']['kbar'])
예제 #2
0
 def test_replace_value_replaces_empty_list_in_target(self):
     target_dict = {'kfoo': []}
     replacement = {'kfoo': ['foo', 'bar']}
     target_dict = utils.replace_value_in_dict(replacement, target_dict)
     self.assertEqual(replacement['kfoo'], target_dict['kfoo'])
예제 #3
0
 def test_replace_value_handles_lists_of_dicts(self):
     target_dict = {'kfoo': [{'kfoo': 'vfoo'}, {'kbar': 'vbar'}]}
     replacement = {'vfoo': 'vbar'}
     target_dict = utils.replace_value_in_dict(replacement, target_dict)
     self.assertEqual(replacement['vfoo'], target_dict['kfoo'][0]['kfoo'])
예제 #4
0
 def test_replace_value_replaces_existing_value_in_list(self):
     target_dict = {'kfoo': ['vfoo', 'vbar']}
     replacement = {'vfoo': 'vbar'}
     target_dict = utils.replace_value_in_dict(replacement, target_dict)
     self.assertEqual(replacement['vfoo'], target_dict['kfoo'][0])
예제 #5
0
 def test_replace_value_ignores_nonexisting_value_in_cascaded_dict(self):
     target_dict = {'kfoo': {'kbar': 'vfoo'}}
     replacement = {'kfoo': 'vbar'}
     modified_dict = utils.replace_value_in_dict(replacement, target_dict)
     self.assertEqual(modified_dict, target_dict)
예제 #6
0
 def test_replace_value_returns_dict(self):
     target_dict = {'kfoo': 'vfoo', 'kbar': 'vbar'}
     replacement = {'kfoo': 'vbar'}
     target_dict = utils.replace_value_in_dict(replacement, target_dict)
     self.assertTrue(isinstance(target_dict, dict))