Skip to content

jdiff.utils.diff_helpers

Diff helpers.

jdiff.utils.diff_helpers.dict_merger(original_dict, dict_to_merge)

Function to merge a dictionary (dict_to_merge) recursively into the original_dict.

jdiff.utils.diff_helpers.fix_deepdiff_key_names(obj)

Return a dict based on the provided dict object where the brackets and quotes are removed from the string.

Parameters:

Name Type Description Default
obj Mapping

Mapping to be fixed. For example:

{
    "root[3]['7.7.7.7']['is_enabled']": {'new_value': False, 'old_value': True},
    "root[3]['7.7.7.7']['is_up']": {'new_value': False, 'old_value': True}
}

required

Returns:

Name Type Description
Dict Dict

aggregated output, for example: {'7.7.7.7': {'is_enabled': {'new_value': False, 'old_value': True}, 'is_up': {'new_value': False, 'old_value': True}}}

jdiff.utils.diff_helpers.get_diff_iterables_items(diff_result)

Helper function for diff_generator to postprocess changes reported by DeepDiff for iterables.

DeepDiff iterable_items are returned when the source data is a list and provided in the format: "root['Ethernet3'][1]" or more generically: root['KEY']['KEY']['KEY']...[numeric_index] where the KEYs are dict keys within the original object and the "[index]" is appended to indicate the position within the list.

Parameters:

Name Type Description Default
diff_result Mapping

iterable comparison result from DeepDiff

required

Returns: Return a dict with new and missing values where the values are in a list.

jdiff.utils.diff_helpers.group_value(tree_list, value)

Function to create a nested Dict by recursively use the tree_list as nested keys.

jdiff.utils.diff_helpers.parse_diff(jdiff_evaluate_response, actual, intended, match_config)

Parse jdiff evaluate result into missing and extra dictionaries.

Dict value in jdiff_evaluate_response can be: - 'missing' -> In the intended but missing from actual. - 'new' -> In the actual missing from intended.

Examples of jdiff_evaluate_response: - {'bar-2': 'missing', 'bar-1': 'new'} - {'hostname': {'new_value': 'veos-actual', 'old_value': 'veos-intended'}, 'domain-name': 'new'} - {'hostname': {'new_value': 'veos-0', 'old_value': 'veos'}, "index_element['ip name']": 'missing', 'domain-name': 'new'} - {'servers': {'server': defaultdict(, {'missing': [{'address': '1.us.pool.ntp.org', 'config': {'address': '1.us.pool.ntp.org'}, 'state': {'address': '1.us.pool.ntp.org'}}]})}}

jdiff.utils.diff_helpers.set_nested_value(data, keys, value)

Recursively sets a value in a nested dictionary, given a list of keys.

Parameters:

Name Type Description Default
data dict

The nested dictionary to modify.

required
keys list

A list of keys to access the target value.

required
value str

The value to set.

required

Returns:

Name Type Description
None None

The function modifies the dictionary in place. Returns None.