Skip to content

Commit 872a72d

Browse files
author
Patryk Szulczewski
committed
post-review updates
1 parent c234680 commit 872a72d

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

netcompare/check_type.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""CheckType Implementation."""
2-
from typing import Mapping, Iterable, Tuple, Union, List, Dict, Any
3-
from .evaluator import diff_generator
4-
from typing import Mapping, Tuple, Union, List, Iterable
2+
from typing import Mapping, Tuple, List, Dict, Any
53
from .evaluator import diff_generator, parameter_evaluator
64
from .runner import extract_values_from_output
75

@@ -30,33 +28,29 @@ def init(*args):
3028
raise NotImplementedError
3129

3230
@staticmethod
33-
def extract_value_from_json_path(output: Union[Mapping, Iterable], path: str, exclude: List = None) -> Any:
31+
def get_value(output: Mapping, path: str, exclude: List = None) -> Any:
3432
"""Return the value contained into a Mapping for a defined path."""
3533
return extract_values_from_output(output, path, exclude)
3634

37-
def evaluate(
38-
self, reference_value: Union[Mapping, Iterable], value_to_compare: Union[Mapping, Iterable]
39-
) -> Tuple[Dict, bool]:
35+
def evaluate(self, reference_value: Any, value_to_compare: Any) -> Tuple[Dict, bool]:
4036
"""Return the result of the evaluation and a boolean True if it passes it or False otherwise.
4137
4238
This method is the one that each CheckType has to implement.
4339
4440
Args:
45-
reference_value: dataset to compare
46-
value_to_compare: dataset to compare
41+
reference_value: Can be any structured data or just a simple value.
42+
value_to_compare: Similar value as above to perform comparison.
4743
4844
Returns:
49-
tuple: Dictionary representing differences between datasets, bool indicating if differences are found.
45+
tuple: Dictionary representing check result, bool indicating if differences are found.
5046
"""
5147
raise NotImplementedError
5248

5349

5450
class ExactMatchType(CheckType):
5551
"""Exact Match class docstring."""
5652

57-
def evaluate(
58-
self, reference_value: Union[Mapping, Iterable], value_to_compare: Union[Mapping, Iterable]
59-
) -> Tuple[Mapping, bool]:
53+
def evaluate(self, reference_value: Any, value_to_compare: Any) -> Tuple[Dict, bool]:
6054
"""Returns the difference between values and the boolean."""
6155
diff = diff_generator(reference_value, value_to_compare)
6256
return diff, not diff
@@ -75,13 +69,13 @@ def __init__(self, *args):
7569
self.tolerance_factor = float(tolerance) / 100
7670
super().__init__()
7771

78-
def evaluate(self, reference_value: Mapping, value_to_compare: Mapping) -> Tuple[Mapping, bool]:
72+
def evaluate(self, reference_value: Mapping, value_to_compare: Mapping) -> Tuple[Dict, bool]:
7973
"""Returns the difference between values and the boolean. Overwrites method in base class."""
8074
diff = diff_generator(reference_value, value_to_compare)
8175
diff = self._get_outliers(diff)
8276
return diff, not diff
8377

84-
def _get_outliers(self, diff: Mapping) -> Mapping:
78+
def _get_outliers(self, diff: Mapping) -> Dict:
8579
"""Return a mapping of values outside the tolerance threshold."""
8680
result = {
8781
key: {sub_key: values for sub_key, values in obj.items() if not self._within_tolerance(**values)}
@@ -98,7 +92,7 @@ def _within_tolerance(self, *, old_value: float, new_value: float) -> bool:
9892
class ParameterMatchType(CheckType):
9993
"""Parameter Match class implementation."""
10094

101-
def evaluate(self, reference_value: Mapping, value_to_compare: Mapping) -> Tuple[Mapping, bool]:
95+
def evaluate(self, reference_value: Mapping, value_to_compare: Mapping) -> Tuple[Dict, bool]:
10296
"""Parameter Match evaluator implementation."""
10397
try:
10498
parameter = value_to_compare[1]

netcompare/evaluator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def fix_deepdiff_key_names(obj: Mapping) -> Dict:
7777
"root[3]['7.7.7.7']['is_up']": {'new_value': False, 'old_value': True}}
7878
7979
Returns:
80-
normalized output Example: {'7.7.7.7': {'is_enabled': {'new_value': False, 'old_value': True},
80+
aggregated output Example: {'7.7.7.7': {'is_enabled': {'new_value': False, 'old_value': True},
8181
'is_up': {'new_value': False, 'old_value': True}}}
8282
"""
8383
pattern = r"'([A-Za-z0-9_\./\\-]*)'"
@@ -106,7 +106,7 @@ def dict_merger(original_dict: Dict, merged_dict: Dict):
106106
original_dict[key] = merged_dict[key]
107107

108108

109-
def parameter_evaluator(values: Mapping, parameter: Mapping) -> Mapping:
109+
def parameter_evaluator(values: Mapping, parameter: Mapping) -> Dict:
110110
"""Parameter Match evaluator engine."""
111111
# value: [{'7.7.7.7': {'peerAddress': '7.7.7.7', 'localAsn': '65130.1100', 'linkType': 'external'}}]
112112
# parameter: {'localAsn': '65130.1100', 'linkType': 'external'}

netcompare/utils/refkey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Reference key utilities."""
2-
from typing import Mapping, List, Union
2+
from typing import Mapping, List, Optional
33

44

5-
def keys_cleaner(wanted_reference_keys: Mapping) -> Union[List[Mapping], None]:
5+
def keys_cleaner(wanted_reference_keys: Mapping) -> Optional[List[Mapping]]:
66
"""Get every required reference key from output."""
77
if isinstance(wanted_reference_keys, list):
88
return wanted_reference_keys

0 commit comments

Comments
 (0)