Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d120639
move jmesparser under utils
lvrfrc87 Nov 19, 2021
bc4d9e5
remove unused import
lvrfrc87 Nov 19, 2021
7f62080
pending changes
chadell Nov 19, 2021
ddc25de
Merge branch 'main' into api-refactor
chadell Nov 19, 2021
05f9bdb
Fixed type_check test
chadell Nov 19, 2021
7aae033
Fix tests
chadell Nov 19, 2021
e48ca3a
commnet
chadell Nov 19, 2021
5049eba
move flatten funcs under utils
lvrfrc87 Nov 19, 2021
74158fb
Merge pull request #3 from networktocode-llc/api-refactor
lvrfrc87 Nov 19, 2021
5aed5c0
move jmesparser under utils
lvrfrc87 Nov 19, 2021
2c46df4
remove unused import
lvrfrc87 Nov 19, 2021
49af479
move flatten funcs under utils
lvrfrc87 Nov 19, 2021
39f834b
Merge branch 'lvrfrc87' of github.com:networktocode-llc/netcompare in…
lvrfrc87 Nov 19, 2021
5361ac9
fix some style errors
lvrfrc87 Nov 19, 2021
a892d15
update path in test task
lvrfrc87 Nov 19, 2021
1a481ce
move key utils under utils
lvrfrc87 Nov 19, 2021
640641a
add tests for lib utils
lvrfrc87 Nov 22, 2021
8069b8e
black refactoring
lvrfrc87 Nov 22, 2021
a19a914
commit save
lvrfrc87 Dec 6, 2021
cffac0a
fix import
lvrfrc87 Dec 6, 2021
0cb20e1
fix var name
lvrfrc87 Dec 6, 2021
62ba209
fix raw compare
lvrfrc87 Dec 6, 2021
70c680a
fix dict return in jmespath
lvrfrc87 Dec 6, 2021
4f124b3
commit save
lvrfrc87 Dec 7, 2021
1e336ee
fix flatten list
lvrfrc87 Dec 7, 2021
284acab
add fefkey typeerror
lvrfrc87 Dec 7, 2021
a914b29
fix example output
lvrfrc87 Dec 7, 2021
88ba66f
improve type
lvrfrc87 Dec 7, 2021
e9d5f2b
Integrate comments from PR
lvrfrc87 Dec 8, 2021
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stages:
- "lint"
- "test"

if: "type IN (pull_request)" # Add in "branch" as an option if desired for branch testing as well
if: "type IN (pull_request)" # Add in "branch" as an option if desired for branch testing as well
language: "python"
services:
- "docker"
Expand All @@ -30,7 +30,7 @@ jobs:
- "pip install invoke toml"
script:
- "invoke black"
- "invoke bandit" # Bandit fails to function on > Py3.8 https://github.com/PyCQA/bandit/issues/639
- "invoke bandit" # Bandit fails to function on > Py3.8 https://github.com/PyCQA/bandit/issues/639
# - "invoke pydocstyle"
- "invoke flake8"
- "invoke yamllint"
Expand Down
4 changes: 2 additions & 2 deletions netcompare/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Pre/Post Check library."""
from .check_type import compare
# from .check_type import compare


__all__ = ["compare"]
# __all__ = ["compare"]
4 changes: 2 additions & 2 deletions netcompare/check_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""CheckType Implementation."""
from typing import Mapping, Iterable, Tuple, Union, List
from typing import Mapping, Tuple, Union, List
from .evaluator import diff_generator
from .runner import extract_values_from_output

Expand All @@ -9,7 +9,6 @@ class CheckType:

def __init__(self, *args):
"""Check Type init method."""
pass

@staticmethod
def init(*args):
Expand All @@ -29,6 +28,7 @@ def extract_value_from_json_path(
"""Return the value contained into a Mapping for a defined path."""
return extract_values_from_output(value, path, exclude)

# TODO: Refine this typing
def evaluate(self, reference_value: Mapping, value_to_compare: Mapping) -> Tuple[Mapping, bool]:
"""Return the result of the evaluation and a boolean True if it passes it or False otherwise.

Expand Down
20 changes: 7 additions & 13 deletions netcompare/evaluator.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
"""Diff evaluator."""
import re
import sys
from deepdiff import DeepDiff
from collections import defaultdict
from collections.abc import Mapping as DictMapping
from functools import partial
from typing import Mapping, List
from typing import Mapping, List, Dict
from deepdiff import DeepDiff

from .runner import extract_values_from_output

sys.path.append(".")


def diff_generator(pre_data: Mapping, post_data: Mapping, check_definition: Mapping) -> Mapping:
def diff_generator(pre_result: Mapping, post_result: Mapping) -> Dict:
"""
Generates diff between pre and post data based on check definition.

Args:
pre_data: pre data result.
post_data: post data result.
check_definition: check definitions.
pre_result: pre data result.
post_result: post data result.

Return:
output: diff between pre and post data.
Expand All @@ -32,9 +29,6 @@ def diff_generator(pre_data: Mapping, post_data: Mapping, check_definition: Mapp
>>> print(diff_generator(check_definition, post_data, check_definition))
{'10.17.254.2': {'state': {'new_value': 'Up', 'old_value': 'Idle'}}}
"""
pre_result = extract_values_from_output(check_definition, pre_data)
post_result = extract_values_from_output(check_definition, post_data)

diff_result = DeepDiff(pre_result, post_result)

result = diff_result.get("values_changed", {})
Expand Down Expand Up @@ -144,7 +138,7 @@ def group_value(tree_list: List, value: Mapping) -> Mapping:
return value


def dict_merger(original_dict: List, merged_dict: Mapping):
def dict_merger(original_dict: Mapping, merged_dict: Mapping):
"""
Merge dictionaries to build final result.

Expand All @@ -158,7 +152,7 @@ def dict_merger(original_dict: List, merged_dict: Mapping):
{'10.17.254.2': {'state': {'new_value': 'Up', 'old_value': 'Idle'}}}
"""
for key in merged_dict.keys():
if key in original_dict and isinstance(original_dict[key], dict) and isinstance(merged_dict[key], DictMapping):
if key in original_dict and isinstance(original_dict[key], dict) and isinstance(merged_dict[key], dict):
dict_merger(original_dict[key], merged_dict[key])
else:
original_dict[key] = merged_dict[key]
Loading