@@ -21,29 +21,17 @@ def test_CheckType_raises_NotImplementedError_for_invalid_check_type():
2121 CheckType .init ("does_not_exist" )
2222
2323
24- def test_CheckType_raises_NotImplementedError_when_calling_check_logic_method ():
25- """Validate that CheckType raises a NotImplementedError when passed a non-existant check_type."""
26- with pytest .raises (NotImplementedError ):
27- CheckType ().check_logic ()
28-
29-
3024exact_match_test_values_no_change = (
3125 ("exact_match" ,),
3226 "api.json" ,
33- {
34- "path" : "result[0].vrfs.default.peerList[*].[$peerAddress$,establishedTransitions]" ,
35- # "reference_key_path": "result[0].vrfs.default.peerList[*].peerAddress",
36- },
27+ "result[0].vrfs.default.peerList[*].[$peerAddress$,establishedTransitions]" ,
3728 ({}, True ),
3829)
3930
4031exact_match_test_values_changed = (
4132 ("exact_match" ,),
4233 "api.json" ,
43- {
44- "path" : "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]" ,
45- # "reference_key_path": "result[0].vrfs.default.peerList[*].peerAddress",
46- },
34+ "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]" ,
4735 (
4836 {
4937 "10.1.0.0" : {"prefixesSent" : {"new_value" : 52 , "old_value" : 50 }},
@@ -56,30 +44,21 @@ def test_CheckType_raises_NotImplementedError_when_calling_check_logic_method():
5644tolerance_test_values_no_change = (
5745 ("tolerance" , 10 ),
5846 "api.json" ,
59- {
60- "path" : "result[0].vrfs.default.peerList[*].[$peerAddress$,establishedTransitions]" ,
61- # "reference_key_path": "result[0].vrfs.default.peerList[*].peerAddress",
62- },
47+ "result[0].vrfs.default.peerList[*].[$peerAddress$,establishedTransitions]" ,
6348 ({}, True ),
6449)
6550
6651tolerance_test_values_within_threshold = (
6752 ("tolerance" , 10 ),
6853 "api.json" ,
69- {
70- "path" : "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]" ,
71- # "reference_key_path": "result[0].vrfs.default.peerList[*].peerAddress",
72- },
54+ "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]" ,
7355 ({}, True ),
7456)
7557
7658tolerance_test_values_beyond_threshold = (
7759 ("tolerance" , 10 ),
7860 "api.json" ,
79- {
80- "path" : "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]" ,
81- # "reference_key_path": "result[0].vrfs.default.peerList[*].peerAddress",
82- },
61+ "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]" ,
8362 (
8463 {
8564 "10.1.0.0" : {"prefixesReceived" : {"new_value" : 120 , "old_value" : 100 }},
@@ -104,41 +83,34 @@ def test_check_type_results(check_type_args, filename, path, expected_results):
10483 check = CheckType .init (* check_type_args )
10584 pre_data = load_json_file ("pre" , filename )
10685 post_data = load_json_file ("post" , filename )
107- actual_results = check .evaluate (pre_data , post_data , path )
86+ pre_value = check .extract_value_from_json_path (pre_data , path )
87+ post_value = check .extract_value_from_json_path (post_data , path )
88+ actual_results = check .evaluate (pre_value , post_value )
10889 assert actual_results == expected_results
10990
11091
11192napalm_bgp_neighbor_status = (
11293 "napalm_get_bgp_neighbors.json" ,
11394 ("exact_match" ,),
114- {
115- "path" : "global.$peers$.*.[is_enabled,is_up]" ,
116- # "reference_key_path": "global.peers"
117- },
95+ "global.$peers$.*.[is_enabled,is_up]" ,
11896 0 ,
11997)
12098
12199napalm_bgp_neighbor_prefixes_ipv4 = (
122100 "napalm_get_bgp_neighbors.json" ,
123101 ("tolerance" , 10 ),
124- {
125- "path" : "global.$peers$.*.*.ipv4.[accepted_prefixes,received_prefixes,sent_prefixes]" ,
126- # "reference_key_path": "global.peers",
127- },
102+ "global.$peers$.*.*.ipv4.[accepted_prefixes,received_prefixes,sent_prefixes]" ,
128103 1 ,
129104)
130105
131106napalm_bgp_neighbor_prefixes_ipv6 = (
132107 "napalm_get_bgp_neighbors.json" ,
133108 ("tolerance" , 10 ),
134- {
135- "path" : "global.$peers$.*.*.ipv6.[accepted_prefixes,received_prefixes,sent_prefixes]" ,
136- # "reference_key_path": "global.peers",
137- },
109+ "global.$peers$.*.*.ipv6.[accepted_prefixes,received_prefixes,sent_prefixes]" ,
138110 2 ,
139111)
140112
141- napalm_get_lldp_neighbors_exact_raw = ("napalm_get_lldp_neighbors.json" , ("exact_match" ,), {} , 0 )
113+ napalm_get_lldp_neighbors_exact_raw = ("napalm_get_lldp_neighbors.json" , ("exact_match" ,), None , 0 )
142114
143115check_tests = [
144116 napalm_bgp_neighbor_status ,
@@ -151,10 +123,13 @@ def test_check_type_results(check_type_args, filename, path, expected_results):
151123@pytest .mark .parametrize ("filename, check_args, path, result_index" , check_tests )
152124def test_checks (filename , check_args , path , result_index ):
153125 """Validate multiple checks on the same data to catch corner cases."""
126+ check = CheckType .init (* check_args )
154127 pre_data = load_json_file ("pre" , filename )
155128 post_data = load_json_file ("post" , filename )
156129 result = load_json_file ("results" , filename )
157130
158- check = CheckType .init (* check_args )
159- check_output = check .evaluate (pre_data , post_data , path )
160- assert list (check_output ) == result [result_index ]
131+ pre_value = check .extract_value_from_json_path (pre_data , path )
132+ post_value = check .extract_value_from_json_path (post_data , path )
133+ actual_results = check .evaluate (pre_value , post_value )
134+
135+ assert list (actual_results ) == result [result_index ]
0 commit comments