Skip to content

Commit a19a914

Browse files
committed
commit save
1 parent 8069b8e commit a19a914

File tree

8 files changed

+46
-59
lines changed

8 files changed

+46
-59
lines changed

netcompare/check_type.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from .evaluator import diff_generator
55
from .runner import extract_values_from_output
66

7-
sys.path.append(".")
8-
97

108
class CheckType:
119
"""Check Type Class."""

netcompare/runner.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import jmespath
44
from typing import Mapping, List, Union
55
from .utils.jmspath_parsers import jmspath_value_parser, jmspath_refkey_parser
6-
from .utils.filter_parsers import exclude_filter, get_values
7-
from .utils.refkey_utils import keys_cleaner, keys_values_zipper
8-
6+
from .utils.filter_parsers import exclude_filter
7+
from .utils.refkey import keys_cleaner, keys_values_zipper, associate_key_of_my_value
8+
from .utils.flatten import flatten_list
9+
import pdb
910

1011
def extract_values_from_output(value: Mapping, path: Mapping, exclude: List) -> Union[Mapping, List, int, str, bool]:
1112
"""Return data from output depending on the check path. See unit text for complete example.
@@ -26,24 +27,45 @@ def extract_values_from_output(value: Mapping, path: Mapping, exclude: List) ->
2627
Return:
2728
[{'7.7.7.7': {'prefixesReceived': 101}}, {'10.1.0.0': {'prefixesReceived': 120}}, ...
2829
"""
29-
# Get the wanted values to be evaluated if jmspath expression is defined.
30+
# Get the wanted values to be evaluated if jmspath expression is defined, otherwise
31+
# use the entire output if jmespath is not defined in check. This cover the "raw" diff type.
3032
if path:
31-
wanted_value = jmespath.search(jmspath_value_parser(path), value)
32-
# Take all the entir output if jmespath is not defined in check. This cover the "raw" diff type.
33-
else:
34-
wanted_value = value
33+
value = jmespath.search(jmspath_value_parser(path), value)
3534

3635
# Exclude filter implementation.
3736
if exclude:
38-
# Update list in place but assign to a new var for name consistency.
39-
exclude_filter(wanted_value, exclude)
40-
filtered_value = wanted_value
37+
exclude_filter(value, exclude)
38+
4139

42-
filtered_value = get_values(path, wanted_value)
40+
# check if list of lists
41+
if not any(isinstance(i, list) for i in value):
42+
raise TypeError(
43+
"Catching value must be defined as list in jmespath expression i.e. result[*].state -> result[*].[state]. You have {}'.".format(
44+
path
45+
)
46+
)
47+
48+
for element in value:
49+
for item in element:
50+
if isinstance(item, dict):
51+
raise TypeError(
52+
'Must be list of lists i.e. [["Idle", 75759616], ["Idle", 75759620]]. You have {}\'.'.format(
53+
value
54+
)
55+
)
56+
elif isinstance(item, list):
57+
flatten_list(value)
58+
break
59+
60+
if path:
61+
paired_key_value = associate_key_of_my_value(jmspath_value_parser(path), value)
62+
else:
63+
paired_key_value = value
4364

65+
pdb.set_trace()
4466
if path and re.search(r"\$.*\$", path):
4567
wanted_reference_keys = jmespath.search(jmspath_refkey_parser(path), value)
4668
list_of_reference_keys = keys_cleaner(wanted_reference_keys)
47-
return keys_values_zipper(list_of_reference_keys, filtered_value)
69+
return keys_values_zipper(list_of_reference_keys, paired_key_value)
4870
else:
49-
return filtered_value
71+
return paired_key_value

netcompare/utils/filter_parsers.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
from typing import Mapping, List
2-
from .jmspath_parsers import jmspath_value_parser
3-
from .flatten_utils import flatten_list
4-
from .refkey_utils import associate_key_of_my_value
5-
62

73
def exclude_filter(data: Mapping, exclude: List):
84
"""
@@ -41,30 +37,3 @@ def exclude_filter(data: Mapping, exclude: List):
4137
for element in data:
4238
if isinstance(element, dict) or isinstance(element, list):
4339
exclude_filter(element, exclude)
44-
45-
46-
def get_values(path: Mapping, wanted_value):
47-
if path:
48-
# check if list of lists
49-
if not any(isinstance(i, list) for i in wanted_value):
50-
raise TypeError(
51-
"Catching value must be defined as list in jmespath expression i.e. result[*].state -> result[*].[state]. You have {}'.".format(
52-
path
53-
)
54-
)
55-
for element in wanted_value:
56-
for item in element:
57-
if isinstance(item, dict):
58-
raise TypeError(
59-
'Must be list of lists i.e. [["Idle", 75759616], ["Idle", 75759620]]. You have {}\'.'.format(
60-
wanted_value
61-
)
62-
)
63-
elif isinstance(item, list):
64-
wanted_value = flatten_list(wanted_value)
65-
break
66-
67-
filtered_value = associate_key_of_my_value(jmspath_value_parser(path), wanted_value)
68-
else:
69-
filtered_value = wanted_value
70-
return filtered_value
File renamed without changes.
File renamed without changes.

tests/test_diff_generator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747

4848
eval_tests = [
4949
exact_match_of_global_peers_via_napalm_getter,
50-
exact_match_of_bgpPeerCaps_via_api,
51-
exact_match_of_bgp_neigh_via_textfsm,
52-
raw_diff_of_interface_ma1_via_api_value_exclude,
53-
raw_diff_of_interface_ma1_via_api_novalue_exclude,
54-
raw_diff_of_interface_ma1_via_api_novalue_noexclude,
55-
exact_match_missing_item,
56-
exact_match_additional_item,
57-
exact_match_changed_item,
58-
exact_match_multi_nested_list,
50+
# exact_match_of_bgpPeerCaps_via_api,
51+
# exact_match_of_bgp_neigh_via_textfsm,
52+
# raw_diff_of_interface_ma1_via_api_value_exclude,
53+
# raw_diff_of_interface_ma1_via_api_novalue_exclude,
54+
# raw_diff_of_interface_ma1_via_api_novalue_noexclude,
55+
# exact_match_missing_item,
56+
# exact_match_additional_item,
57+
# exact_match_changed_item,
58+
# exact_match_multi_nested_list,
5959
]
6060

6161

tests/test_refkey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from netcompare.utils.refkey_utils import keys_cleaner, keys_values_zipper, associate_key_of_my_value
2+
from netcompare.utils.refkey import keys_cleaner, keys_values_zipper, associate_key_of_my_value
33

44

55
assertion_failed_message = """Test output is different from expected output.

tests/test_type_check.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from .utility import load_json_file
44
from netcompare.check_type import CheckType, ExactMatchType, ToleranceType
55

6-
sys.path.append("..")
7-
86

97
@pytest.mark.parametrize(
108
"args, expected_class",

0 commit comments

Comments
 (0)