Skip to content

Commit 00ee630

Browse files
committed
more testing
1 parent 683bd01 commit 00ee630

File tree

1 file changed

+29
-46
lines changed

1 file changed

+29
-46
lines changed

tests/test_diff_helpers.py

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""DIff helpers unit tests."""
22

3-
from collections import defaultdict
4-
53
import pytest
64

5+
from jdiff.check_types import CheckType
76
from jdiff.utils.diff_helpers import (
87
_parse_index_element_string,
98
dict_merger,
@@ -33,12 +32,16 @@ def test_group_value():
3332
"""Tests that nested dict is recursively created."""
3433
tree_list = ["10.1.0.0", "is_enabled"]
3534
value = {"new_value": False, "old_value": True}
36-
assert group_value(tree_list, value) == {"10.1.0.0": {"is_enabled": {"new_value": False, "old_value": True}}}
35+
assert group_value(tree_list, value) == {
36+
"10.1.0.0": {"is_enabled": {"new_value": False, "old_value": True}}
37+
}
3738

3839

3940
def test_fix_deepdiff_key_names():
4041
"""Tests that deepdiff return is parsed properly."""
41-
deepdiff_object = {"root[0]['10.1.0.0']['is_enabled']": {"new_value": False, "old_value": True}}
42+
deepdiff_object = {
43+
"root[0]['10.1.0.0']['is_enabled']": {"new_value": False, "old_value": True}
44+
}
4245
assert fix_deepdiff_key_names(deepdiff_object) == {
4346
"10.1.0.0": {"is_enabled": {"new_value": False, "old_value": True}}
4447
}
@@ -47,7 +50,9 @@ def test_fix_deepdiff_key_names():
4750
def test_get_diff_iterables_items():
4851
"""Tests that deepdiff return is parsed properly."""
4952
diff_result = {
50-
"values_changed": {"root['Ethernet1'][0]['port']": {"new_value": "518", "old_value": "519"}},
53+
"values_changed": {
54+
"root['Ethernet1'][0]['port']": {"new_value": "518", "old_value": "519"}
55+
},
5156
"iterable_item_added": {
5257
"root['Ethernet3'][1]": {
5358
"hostname": "ios-xrv-unittest",
@@ -58,7 +63,9 @@ def test_get_diff_iterables_items():
5863
result = get_diff_iterables_items(diff_result)
5964

6065
assert list(dict(result).keys())[0] == "['Ethernet3']"
61-
assert list(list(dict(result).values())[0].values())[0] == [{"hostname": "ios-xrv-unittest", "port": "Gi0/0/0/0"}]
66+
assert list(list(dict(result).values())[0].values())[0] == [
67+
{"hostname": "ios-xrv-unittest", "port": "Gi0/0/0/0"}
68+
]
6269

6370

6471
index_element_case_1 = (
@@ -82,11 +89,15 @@ def test__parse_index_element_string(index_element, result):
8289
assert parsed_result == result
8390

8491

92+
parse_diff_simple_1 = (
93+
{"foo": {"bar-1": "baz1"}}, # actual
94+
{"foo": {"bar-2": "baz2"}}, # intended
95+
"foo", # match_config
96+
{"bar-1": "baz1"}, # extra
97+
{"bar-2": "baz2"}, # missing
98+
)
99+
85100
parse_diff_case_1 = (
86-
{
87-
"hostname": {"new_value": "veos", "old_value": "veos-0"},
88-
"domain-name": "missing",
89-
},
90101
{"openconfig-system:config": {"domain-name": "ntc.com", "hostname": "veos-0"}},
91102
{"openconfig-system:config": {"hostname": "veos"}},
92103
"openconfig-system:config",
@@ -95,11 +106,6 @@ def test__parse_index_element_string(index_element, result):
95106
)
96107

97108
parse_diff_case_2 = (
98-
{
99-
"hostname": {"new_value": "veos", "old_value": "veos-0"},
100-
"domain-name": "missing",
101-
"index_element['openconfig-system:config']['ip name']": "new",
102-
},
103109
{"openconfig-system:config": {"domain-name": "ntc.com", "hostname": "veos-0"}},
104110
{"openconfig-system:config": {"hostname": "veos", "ip name": "ntc.com"}},
105111
"openconfig-system:config",
@@ -108,11 +114,6 @@ def test__parse_index_element_string(index_element, result):
108114
)
109115

110116
parse_diff_case_3 = (
111-
{
112-
"domain-name": "missing",
113-
"hostname": "missing",
114-
"index_element['openconfig-system:config']['ip name']": "new",
115-
},
116117
{"openconfig-system:config": {"domain-name": "ntc.com", "hostname": "veos-0"}},
117118
{"openconfig-system:config": {"ip name": "ntc.com"}},
118119
"openconfig-system:config",
@@ -121,7 +122,6 @@ def test__parse_index_element_string(index_element, result):
121122
)
122123

123124
parse_diff_case_4 = (
124-
{"domain-name": "missing"},
125125
{"openconfig-system:config": {"domain-name": "ntc.com", "hostname": "veos"}},
126126
{"openconfig-system:config": {"hostname": "veos"}},
127127
"openconfig-system:config",
@@ -130,11 +130,6 @@ def test__parse_index_element_string(index_element, result):
130130
)
131131

132132
parse_diff_case_5 = (
133-
{
134-
"hostname": {"new_value": "veos", "old_value": "veos-0"},
135-
"domain-name": "missing",
136-
"index_element['openconfig-system:config']['ip name']": "new",
137-
},
138133
{"openconfig-system:config": {"domain-name": "ntc.com", "hostname": "veos-0"}},
139134
{"openconfig-system:config": {"hostname": "veos", "ip name": "ntc.com"}},
140135
"openconfig-system:config",
@@ -143,22 +138,6 @@ def test__parse_index_element_string(index_element, result):
143138
)
144139

145140
parse_diff_case_6 = (
146-
{
147-
"servers": {
148-
"server": defaultdict(
149-
list,
150-
{
151-
"new": [
152-
{
153-
"address": "1.us.pool.ntp.org",
154-
"config": {"address": "1.us.pool.ntp.org"},
155-
"state": {"address": "1.us.pool.ntp.org"},
156-
}
157-
]
158-
},
159-
)
160-
}
161-
},
162141
{"openconfig-system:ntp": {"servers": {"server": []}}},
163142
{
164143
"openconfig-system:ntp": {
@@ -193,6 +172,7 @@ def test__parse_index_element_string(index_element, result):
193172
)
194173

195174
parse_diff_tests = [
175+
parse_diff_simple_1,
196176
parse_diff_case_1,
197177
parse_diff_case_2,
198178
parse_diff_case_3,
@@ -203,18 +183,21 @@ def test__parse_index_element_string(index_element, result):
203183

204184

205185
@pytest.mark.parametrize(
206-
"jdiff_evaluate_response, actual, intended, match_config, extra, missing",
186+
"actual, intended, match_config, extra, missing",
207187
parse_diff_tests,
208188
)
209-
def test_parse_diff(
210-
jdiff_evaluate_response, actual, intended, match_config, extra, missing
211-
): # pylint: disable=too-many-arguments
189+
def test_parse_diff(actual, intended, match_config, extra, missing): # pylint: disable=too-many-arguments
212190
"""Test that index_element can be unpacked."""
191+
jdiff_param_match = CheckType.create("exact_match")
192+
jdiff_evaluate_response, _ = jdiff_param_match.evaluate(actual, intended)
193+
print(jdiff_evaluate_response)
194+
213195
parsed_extra, parsed_missing = parse_diff(
214196
jdiff_evaluate_response,
215197
actual,
216198
intended,
217199
match_config,
218200
)
201+
print(parsed_extra, parsed_missing)
219202
assert parsed_extra == extra
220203
assert parsed_missing == missing

0 commit comments

Comments
 (0)