Skip to content

Commit 8ff1558

Browse files
committed
Merge branch 'lvrfrc87' of github.com:networktocode-llc/netcompare into lvrfrc87
2 parents 59ad3f8 + 66a2723 commit 8ff1558

File tree

7 files changed

+60
-47
lines changed

7 files changed

+60
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
strategy:
160160
fail-fast: true
161161
matrix:
162-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
162+
python-version: ["3.7", "3.8", "3.9", "3.10"]
163163
runs-on: "ubuntu-20.04"
164164
env:
165165
PYTHON_VER: "${{ matrix.python-version }}"

netcompare/check_types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def evaluate(self, *args, **kwargs) -> Tuple[Dict, bool]:
125125
tuple: Dictionary representing check result, bool indicating if differences are found.
126126
"""
127127
# This method should call before any other logic the validation of the arguments
128-
# self.validate(**kwargs)
128+
# self._validate(**kwargs)
129129

130130
@staticmethod
131131
@abstractmethod
@@ -145,7 +145,7 @@ def _validate(referece_data):
145145
# No need for _validate method as exact-match does not take any specific arguments.
146146
pass
147147

148-
def evaluate(self, value_to_compare: Any, reference_data: Any) -> Tuple[Dict, bool]:
148+
def evaluate(self, value_to_compare: Any, reference_data: Any) -> Tuple[Dict, bool]: # type: ignore[override]
149149
"""Returns the difference between values and the boolean."""
150150

151151
evaluation_result = diff_generator(reference_data, value_to_compare)
@@ -166,7 +166,7 @@ def _validate(tolerance) -> None:
166166
if tolerance < 0:
167167
raise ValueError(f"Tolerance value must be greater than 0. You have: {tolerance}.")
168168

169-
def evaluate(self, value_to_compare: Any, reference_data: Any, tolerance: int) -> Tuple[Dict, bool]:
169+
def evaluate(self, value_to_compare: Any, reference_data: Any, tolerance: int) -> Tuple[Dict, bool]: # type: ignore[override]
170170
"""Returns the difference between values and the boolean. Overwrites method in base class."""
171171
self._validate(tolerance=tolerance)
172172
evaluation_result = diff_generator(reference_data, value_to_compare)
@@ -219,7 +219,7 @@ def _validate(params, mode) -> None:
219219
f"'mode' argument should be one of the following: {', '.join(mode_options)}. You have: {mode}"
220220
)
221221

222-
def evaluate(self, value_to_compare: Mapping, params: Dict, mode: str) -> Tuple[Dict, bool]:
222+
def evaluate(self, value_to_compare: Mapping, params: Dict, mode: str) -> Tuple[Dict, bool]: # type: ignore[override]
223223
"""Parameter Match evaluator implementation."""
224224
self._validate(params=params, mode=mode)
225225
# TODO: we don't use the mode?
@@ -244,7 +244,7 @@ def _validate(regex, mode) -> None:
244244
if mode not in mode_options:
245245
raise ValueError(f"'mode' argument should be {mode_options}. You have: {mode}")
246246

247-
def evaluate(self, value_to_compare: Mapping, regex: str, mode: str) -> Tuple[Mapping, bool]:
247+
def evaluate(self, value_to_compare: Mapping, regex: str, mode: str) -> Tuple[Dict, bool]: # type: ignore[override]
248248
"""Regex Match evaluator implementation."""
249249
self._validate(regex=regex, mode=mode)
250250
evaluation_result = regex_evaluator(value_to_compare, regex, mode)
@@ -327,7 +327,7 @@ def _validate(params) -> None:
327327
f"check option all-same must have value of type bool. You have: {params_value} of type {type(params_value)}"
328328
)
329329

330-
def evaluate(self, value_to_compare: Any, params: Any) -> Tuple[Dict, bool]:
330+
def evaluate(self, value_to_compare: Any, params: Any) -> Tuple[Dict, bool]: # type: ignore[override]
331331
"""Operator evaluator implementation."""
332332
self._validate(params)
333333
# For name consistency.

netcompare/operator.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, reference_data: Any, value_to_compare: Any) -> None:
1515
self.reference_data = reference_data
1616
self.value_to_compare = value_to_compare
1717

18-
def _loop_through_wrapper(self, call_ops: str) -> Tuple[bool, List]:
18+
def _loop_through_wrapper(self, call_ops: str) -> Tuple[List, bool]:
1919
"""Private wrapper method for operator evaluation based on 'operator' lib.
2020
2121
Based on value passed to the method, the appropriate operator logic is triggered.
@@ -58,7 +58,7 @@ def call_evaluation_logic():
5858
"not_contains": operator.contains,
5959
}
6060

61-
result = []
61+
result = [] # type: List
6262
for item in self.value_to_compare:
6363
for value in item.values():
6464
for evaluated_value in value.values():
@@ -73,10 +73,8 @@ def all_same(self) -> Tuple[bool, Any]:
7373
result = []
7474

7575
for item in self.value_to_compare:
76-
for value in item.values():
77-
# Create a list for compare values.
78-
list_of_values.append(value)
79-
76+
# Create a list for compare values.
77+
list_of_values.extend(iter(item.values()))
8078
for element in list_of_values:
8179
if element != list_of_values[0]:
8280
result.append(False)
@@ -91,34 +89,34 @@ def all_same(self) -> Tuple[bool, Any]:
9189
return (self.value_to_compare, True)
9290
return (self.value_to_compare, False)
9391

94-
def contains(self) -> Tuple[bool, List]:
92+
def contains(self) -> Tuple[List, bool]:
9593
"""Contains operator caller."""
9694
return self._loop_through_wrapper("contains")
9795

98-
def not_contains(self) -> Tuple[bool, List]:
96+
def not_contains(self) -> Tuple[List, bool]:
9997
"""Not contains operator caller."""
10098
return self._loop_through_wrapper("not_contains")
10199

102-
def is_gt(self) -> Tuple[bool, List]:
100+
def is_gt(self) -> Tuple[List, bool]:
103101
"""Is greather than operator caller."""
104102
return self._loop_through_wrapper(">")
105103

106-
def is_lt(self) -> Tuple[bool, List]:
104+
def is_lt(self) -> Tuple[List, bool]:
107105
"""Is lower than operator caller."""
108106
return self._loop_through_wrapper("<")
109107

110-
def is_in(self) -> Tuple[bool, List]:
108+
def is_in(self) -> Tuple[List, bool]:
111109
"""Is in operator caller."""
112110
return self._loop_through_wrapper("is_in")
113111

114-
def not_in(self) -> Tuple[bool, List]:
112+
def not_in(self) -> Tuple[List, bool]:
115113
"""Is not in operator caller."""
116114
return self._loop_through_wrapper("not_in")
117115

118-
def in_range(self) -> Tuple[bool, List]:
116+
def in_range(self) -> Tuple[List, bool]:
119117
"""Is in range operator caller."""
120118
return self._loop_through_wrapper("in_range")
121119

122-
def not_range(self) -> Tuple[bool, List]:
120+
def not_range(self) -> Tuple[List, bool]:
123121
"""Is not in range operator caller."""
124122
return self._loop_through_wrapper("not_range")

netcompare/utils/diff_helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import re
33
from collections import defaultdict
44
from functools import partial
5-
from typing import Mapping, Dict, List
5+
from typing import Mapping, Dict, List, DefaultDict
66

77
REGEX_PATTERN_RELEVANT_KEYS = r"'([A-Za-z0-9_\./\\-]*)'"
88

99

10-
def get_diff_iterables_items(diff_result: Mapping) -> Dict:
10+
def get_diff_iterables_items(diff_result: Mapping) -> DefaultDict:
1111
"""Helper function for diff_generator to postprocess changes reported by DeepDiff for iterables.
1212
1313
DeepDiff iterable_items are returned when the source data is a list
@@ -24,7 +24,7 @@ def get_diff_iterables_items(diff_result: Mapping) -> Dict:
2424
get_dict_keys = re.compile(r"^root((\['\w.*'\])+)\[\d+\]$")
2525

2626
defaultdict_list = partial(defaultdict, list)
27-
result = defaultdict(defaultdict_list)
27+
result = defaultdict(defaultdict_list) # type: DefaultDict
2828

2929
items_removed = diff_result.get("iterable_item_removed")
3030
if items_removed:
@@ -59,7 +59,7 @@ def fix_deepdiff_key_names(obj: Mapping) -> Dict:
5959
Dict: aggregated output, for example: {'7.7.7.7': {'is_enabled': {'new_value': False, 'old_value': True},
6060
'is_up': {'new_value': False, 'old_value': True}}}
6161
"""
62-
result = {}
62+
result = {} # type: Dict
6363
for key, value in obj.items():
6464
key_parts = re.findall(REGEX_PATTERN_RELEVANT_KEYS, key)
6565
if not key_parts: # If key parts can't be find, keep original key so data is not lost.

poetry.lock

Lines changed: 20 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,19 @@ testpaths = [
107107
"tests"
108108
]
109109
addopts = "-vv --doctest-modules"
110+
111+
[tool.mypy]
112+
exclude = [
113+
'^tasks\.py',
114+
]
115+
116+
[[tool.mypy.overrides]]
117+
module = [
118+
"deepdiff",
119+
"jmespath",
120+
]
121+
ignore_missing_imports = true
122+
123+
[[tool.mypy.overrides]]
124+
module = "tests.*"
125+
ignore_errors = true

tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,5 @@ def tests(context, path=".", local=INVOKE_LOCAL):
172172
pydocstyle(context, path, local)
173173
bandit(context, path, local)
174174
pytest(context, local)
175-
# mypy(context, local)
175+
mypy(context, path, local)
176176
print("All tests have passed!")

0 commit comments

Comments
 (0)