Skip to content

Commit c00c6f3

Browse files
pszulczewskiPatryk Szulczewski
andauthored
handle duplication when fixing keys. (#34)
Co-authored-by: Patryk Szulczewski <patryk.szulczewski@networktocode.com>
1 parent 1631a6d commit c00c6f3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

netcompare/utils/diff_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ def dict_merger(original_dict: Dict, dict_to_merge: Dict):
7777
for key in dict_to_merge.keys():
7878
if key in original_dict and isinstance(original_dict[key], dict) and isinstance(dict_to_merge[key], dict):
7979
dict_merger(original_dict[key], dict_to_merge[key])
80+
elif key in original_dict.keys():
81+
original_dict[key + "_dup!"] = dict_to_merge[key] # avoid overwriting existing keys.
8082
else:
8183
original_dict[key] = dict_to_merge[key]

tests/test_diff_generator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@
131131
},
132132
)
133133

134-
textfsm_ospf_int_br_exact_match = (
134+
exact_match_textfsm_ospf_int_br_raw = (
135+
"textfsm_ospf_int_br",
136+
"",
137+
[],
138+
{"state": {"new_value": "DOWN", "old_value": "P2P", "new_value_dup!": "DR", "old_value_dup!": "BDR"}},
139+
)
140+
141+
exact_match_textfsm_ospf_int_br_normalized = (
135142
"textfsm_ospf_int_br",
136143
"[*].[$interface$,area,ip_address_mask,cost,state,neighbors_fc]",
137144
[],
@@ -152,7 +159,8 @@
152159
exact_match_additional_item,
153160
exact_match_changed_item,
154161
exact_match_multi_nested_list,
155-
textfsm_ospf_int_br_exact_match,
162+
exact_match_textfsm_ospf_int_br_raw,
163+
exact_match_textfsm_ospf_int_br_normalized,
156164
]
157165

158166

0 commit comments

Comments
 (0)