Skip to content

Commit 640641a

Browse files
committed
add tests for lib utils
1 parent 1a481ce commit 640641a

19 files changed

+119
-77
lines changed

netcompare/check_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""CheckType Implementation."""
2+
import sys
23
from typing import Mapping, Tuple, Union, List
34
from .evaluator import diff_generator
45
from .runner import extract_values_from_output
56

7+
sys.path.append(".")
8+
69

710
class CheckType:
811
"""Check Type Class."""

netcompare/runner.py

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import re
33
import jmespath
44
from typing import Mapping, List, Union
5-
from .utils.jmspath.parsers import jmspath_value_parser, jmspath_refkey_parser
6-
from .utils.data.parsers import exclude_filter, get_values
7-
from .utils.refkey.utils import keys_cleaner, keys_values_zipper
5+
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
88

99

1010
def extract_values_from_output(value: Mapping, path: Mapping, exclude: List) -> Union[Mapping, List, int, str, bool]:
@@ -49,46 +49,5 @@ def extract_values_from_output(value: Mapping, path: Mapping, exclude: List) ->
4949
return filtered_value
5050

5151

52-
def associate_key_of_my_value(paths: Mapping, wanted_value: List) -> List:
53-
"""
54-
Associate each key defined in path to every value found in output.
55-
56-
Args:
57-
paths: {"path": "global.peers.*.[is_enabled,is_up]"}
58-
wanted_value: [[True, False], [True, False], [True, False], [True, False]]
59-
60-
Return:
61-
[{'is_enabled': True, 'is_up': False}, ...
62-
63-
Example:
64-
>>> from runner import associate_key_of_my_value
65-
>>> path = {"path": "global.peers.*.[is_enabled,is_up]"}
66-
>>> wanted_value = [[True, False], [True, False], [True, False], [True, False]]
67-
{'is_enabled': True, 'is_up': False}, {'is_enabled': True, 'is_up': False}, ...
68-
"""
69-
70-
# global.peers.*.[is_enabled,is_up] / result.[*].state
71-
find_the_key_of_my_values = paths.split(".")[-1]
72-
73-
# [is_enabled,is_up]
74-
if find_the_key_of_my_values.startswith("[") and find_the_key_of_my_values.endswith("]"):
75-
# ['is_enabled', 'is_up']
76-
my_key_value_list = find_the_key_of_my_values.strip("[]").split(",")
77-
# state
78-
else:
79-
my_key_value_list = [find_the_key_of_my_values]
80-
81-
final_list = list()
82-
83-
for items in wanted_value:
84-
temp_dict = dict()
85-
86-
if len(items) != len(my_key_value_list):
87-
raise ValueError("Key's value len != from value len")
88-
89-
for my_index, my_value in enumerate(items):
90-
temp_dict.update({my_key_value_list[my_index]: my_value})
91-
final_list.append(temp_dict)
9252

93-
return final_list
9453

File renamed without changes.

netcompare/utils/data/tests/__init__.py

Whitespace-only changes.

netcompare/utils/data/parsers.py renamed to netcompare/utils/filter_parsers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Mapping, List
2-
from ..jmspath.parsers import jmspath_value_parser
3-
from ..list.flatten import flatten_list
4-
from ...runner import associate_key_of_my_value
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
55

66

77
def exclude_filter(data: Mapping, exclude: List):
File renamed without changes.

netcompare/utils/jmspath/__init__.py

Whitespace-only changes.

netcompare/utils/jmspath/tests/__init__.py

Whitespace-only changes.
File renamed without changes.

netcompare/utils/list/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)