Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions netcompare/check_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _validate(**kwargs) -> None:
"""Method to validate arguments."""
# reference_data = getattr(kwargs, "reference_data")

def evaluate(self, value_to_compare: Any, reference_data: Any) -> Tuple[Dict, bool]:
def evaluate(self, value_to_compare: Any, reference_data: Any) -> Tuple[Dict, bool]: # type: ignore[override]
"""Returns the difference between values and the boolean."""
self._validate(reference_data=reference_data)
evaluation_result = diff_generator(reference_data, value_to_compare)
Expand All @@ -168,7 +168,7 @@ def _validate(**kwargs) -> None:
if tolerance < 0:
raise ValueError(f"Tolerance value must be greater than 0. You have: {tolerance}.")

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

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

def evaluate(self, value_to_compare: Mapping, regex: str, mode: str) -> Tuple[Mapping, bool]:
def evaluate(self, value_to_compare: Mapping, regex: str, mode: str) -> Tuple[Dict, bool]: # type: ignore[override]
"""Regex Match evaluator implementation."""
self._validate(regex=regex, mode=mode)
evaluation_result = regex_evaluator(value_to_compare, regex, mode)
Expand Down Expand Up @@ -332,7 +332,7 @@ def _validate(**kwargs) -> None:
f"check option all-same must have value of type bool. You have: {params_value} of type {type(params_value)}"
)

def evaluate(self, value_to_compare: Any, params: Any) -> Tuple[Dict, bool]:
def evaluate(self, value_to_compare: Any, params: Any) -> Tuple[Dict, bool]: # type: ignore[override]
"""Operator evaluator implementation."""
self._validate(**params)
# For name consistency.
Expand Down
26 changes: 12 additions & 14 deletions netcompare/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, reference_data: Any, value_to_compare: Any) -> None:
self.reference_data = reference_data
self.value_to_compare = value_to_compare

def _loop_through_wrapper(self, call_ops: str) -> Tuple[bool, List]:
def _loop_through_wrapper(self, call_ops: str) -> Tuple[List, bool]:
"""Private wrapper method for operator evaluation based on 'operator' lib.

Based on value passed to the method, the appropriate operator logic is triggered.
Expand Down Expand Up @@ -58,7 +58,7 @@ def call_evaluation_logic():
"not_contains": operator.contains,
}

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

for item in self.value_to_compare:
for value in item.values():
# Create a list for compare values.
list_of_values.append(value)

# Create a list for compare values.
list_of_values.extend(iter(item.values()))
for element in list_of_values:
if element != list_of_values[0]:
result.append(False)
Expand All @@ -91,34 +89,34 @@ def all_same(self) -> Tuple[bool, Any]:
return (self.value_to_compare, True)
return (self.value_to_compare, False)

def contains(self) -> Tuple[bool, List]:
def contains(self) -> Tuple[List, bool]:
"""Contains operator caller."""
return self._loop_through_wrapper("contains")

def not_contains(self) -> Tuple[bool, List]:
def not_contains(self) -> Tuple[List, bool]:
"""Not contains operator caller."""
return self._loop_through_wrapper("not_contains")

def is_gt(self) -> Tuple[bool, List]:
def is_gt(self) -> Tuple[List, bool]:
"""Is greather than operator caller."""
return self._loop_through_wrapper(">")

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

def is_in(self) -> Tuple[bool, List]:
def is_in(self) -> Tuple[List, bool]:
"""Is in operator caller."""
return self._loop_through_wrapper("is_in")

def not_in(self) -> Tuple[bool, List]:
def not_in(self) -> Tuple[List, bool]:
"""Is not in operator caller."""
return self._loop_through_wrapper("not_in")

def in_range(self) -> Tuple[bool, List]:
def in_range(self) -> Tuple[List, bool]:
"""Is in range operator caller."""
return self._loop_through_wrapper("in_range")

def not_range(self) -> Tuple[bool, List]:
def not_range(self) -> Tuple[List, bool]:
"""Is not in range operator caller."""
return self._loop_through_wrapper("not_range")
8 changes: 4 additions & 4 deletions netcompare/utils/diff_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import re
from collections import defaultdict
from functools import partial
from typing import Mapping, Dict, List
from typing import Mapping, Dict, List, DefaultDict

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


def get_diff_iterables_items(diff_result: Mapping) -> Dict:
def get_diff_iterables_items(diff_result: Mapping) -> DefaultDict:
"""Helper function for diff_generator to postprocess changes reported by DeepDiff for iterables.

DeepDiff iterable_items are returned when the source data is a list
Expand All @@ -24,7 +24,7 @@ def get_diff_iterables_items(diff_result: Mapping) -> Dict:
get_dict_keys = re.compile(r"^root((\['\w.*'\])+)\[\d+\]$")

defaultdict_list = partial(defaultdict, list)
result = defaultdict(defaultdict_list)
result = defaultdict(defaultdict_list) # type: DefaultDict

items_removed = diff_result.get("iterable_item_removed")
if items_removed:
Expand Down Expand Up @@ -59,7 +59,7 @@ def fix_deepdiff_key_names(obj: Mapping) -> Dict:
Dict: aggregated output, for example: {'7.7.7.7': {'is_enabled': {'new_value': False, 'old_value': True},
'is_up': {'new_value': False, 'old_value': True}}}
"""
result = {}
result = {} # type: Dict
for key, value in obj.items():
key_parts = re.findall(REGEX_PATTERN_RELEVANT_KEYS, key)
if not key_parts: # If key parts can't be find, keep original key so data is not lost.
Expand Down
41 changes: 20 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,19 @@ testpaths = [
"tests"
]
addopts = "-vv --doctest-modules"

[tool.mypy]
exclude = [
'^tasks\.py',
]

[[tool.mypy.overrides]]
module = [
"deepdiff",
"jmespath",
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "tests.*"
ignore_errors = true
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ def tests(context, path=".", local=INVOKE_LOCAL):
pydocstyle(context, path, local)
bandit(context, path, local)
pytest(context, local)
# mypy(context, local)
mypy(context, path, local)
print("All tests have passed!")