예제 #1
0
 def test_change_dict_keys_missing_key(self):
     """
     Given
         - dictionary to be changed
         - dictionary with new keys' names
     When
         - the output dictionary is missing a key to be changed
     Then
         - change only the keys that exist
     """
     new_names_dict = {'old_name_1': 'new_name_1',
                       'old_name_2': 'new_name_2'}
     dict_to_change = {'old_name_2': 'some_value_2'}
     changed_dict = change_dict_keys(new_names_dict, dict_to_change)
     assert changed_dict['new_name_2']
     assert 'new_name_1' not in changed_dict
     assert 'old_name_1' not in changed_dict
     assert 'old_name_2' not in changed_dict
예제 #2
0
 def test_change_dict_keys_output_is_none(self):
     """
     Given
         - dictionary to be changed
         - dictionary with new keys' names
     When
         - the output dictionary is None
     Then
         - raise a TypeError Exception
     """
     with pytest.raises(TypeError):
         new_names_dict = {'old_name_1': 'new_name_1',
                           'old_name_2': 'new_name_2'}
         dict_to_change = None
         changed_dict = change_dict_keys(new_names_dict, dict_to_change)
         assert changed_dict['new_name_1']
         assert changed_dict['new_name_2']
         assert 'old_name_1' not in changed_dict
         assert 'old_name_2' not in changed_dict
예제 #3
0
 def test_change_dict_keys_expected_format(self):
     """
     Given
         - dictionary to be changed
         - dictionary with new keys' names
     When
         - the dictionaries are well formatted
     Then
         -  return the dictionary with the new keys
     """
     new_names_dict = {'old_name_1': 'new_name_1',
                       'old_name_2': 'new_name_2'}
     dict_to_change = {'old_name_1': 'some_value_1',
                       'old_name_2': 'some_value_2'}
     changed_dict = change_dict_keys(new_names_dict, dict_to_change)
     assert changed_dict['new_name_1']
     assert changed_dict['new_name_2']
     assert 'old_name_1' not in changed_dict
     assert 'old_name_2' not in changed_dict