Skip to content

Commit fa66e68

Browse files
author
Patryk Szulczewski
committed
Fix tests.
1 parent f683606 commit fa66e68

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

netcompare/check_types.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def evaluate(self, *args, **kwargs) -> Tuple[Dict, bool]:
129129

130130
@staticmethod
131131
@abstractmethod
132-
def _validate(**kwargs) -> None:
132+
def _validate(*args) -> None:
133133
"""Method to validate arguments that raises proper exceptions."""
134134

135135
@staticmethod
@@ -141,13 +141,13 @@ def result(evaluation_result) -> Tuple[Dict, bool]:
141141
class ExactMatchType(CheckType):
142142
"""Exact Match class docstring."""
143143

144-
def _validate(referece_data):
144+
@staticmethod
145+
def _validate(reference_data):
145146
# No need for _validate method as exact-match does not take any specific arguments.
146147
pass
147148

148149
def evaluate(self, value_to_compare: Any, reference_data: Any) -> Tuple[Dict, bool]: # type: ignore[override]
149150
"""Returns the difference between values and the boolean."""
150-
151151
evaluation_result = diff_generator(reference_data, value_to_compare)
152152
return self.result(evaluation_result)
153153

@@ -156,7 +156,7 @@ class ToleranceType(CheckType):
156156
"""Tolerance class docstring."""
157157

158158
@staticmethod
159-
def _validate(tolerance) -> None:
159+
def _validate(tolerance) -> None: # type: ignore[override]
160160
"""Method to validate arguments."""
161161
# reference_data = getattr(kwargs, "reference_data")
162162
if not tolerance:
@@ -204,7 +204,7 @@ class ParameterMatchType(CheckType):
204204
"""Parameter Match class implementation."""
205205

206206
@staticmethod
207-
def _validate(params, mode) -> None:
207+
def _validate(params, mode) -> None: # type: ignore[override]
208208
"""Method to validate arguments."""
209209
mode_options = ["match", "no-match"]
210210
if not params:
@@ -231,7 +231,7 @@ class RegexType(CheckType):
231231
"""Regex Match class implementation."""
232232

233233
@staticmethod
234-
def _validate(regex, mode) -> None:
234+
def _validate(regex, mode) -> None: # type: ignore[override]
235235
"""Method to validate arguments."""
236236
mode_options = ["match", "no-match"]
237237
if not regex:
@@ -255,7 +255,7 @@ class OperatorType(CheckType):
255255
"""Operator class implementation."""
256256

257257
@staticmethod
258-
def _validate(params) -> None:
258+
def _validate(params) -> None: # type: ignore[override]
259259
"""Validate operator parameters."""
260260
in_operators = ("is-in", "not-in", "in-range", "not-range")
261261
bool_operators = ("all-same",)
@@ -273,8 +273,8 @@ def _validate(params) -> None:
273273
if not params or list(params.keys())[0] != "params":
274274
raise ValueError(f"'params' argument must be provided. You have: {list(params.keys())[0]}.")
275275

276-
params_key = params.get("mode")
277-
params_value = params.get("operator_data")
276+
params_key = params.get("params", {}).get("mode")
277+
params_value = params.get("params", {}).get("operator_data")
278278

279279
if not params_key or not params_value:
280280
raise ValueError(

tasks.py

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

tests/test_type_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CheckTypeChild(CheckType):
2626
"""Test Class."""
2727

2828
@staticmethod
29-
def _validate(**kwargs):
29+
def _validate(*args):
3030
return None
3131

3232
def evaluate(self, *args, **kwargs):

tests/test_validates.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@
122122

123123

124124
@pytest.mark.parametrize("check_type_str, evaluate_args, expected_results", all_tests)
125-
def test_tolerance_key_name(check_type_str, evaluate_args, expected_results):
125+
def test_validate_arguments(check_type_str, evaluate_args, expected_results):
126126
"""Test CheckType validate method for each check-type."""
127127
check = CheckType.init(check_type_str)
128128

129129
with pytest.raises(ValueError) as exc_info:
130-
if check_type_str == 'tolerance':
131-
check._validate(tolerance=evaluate_args)
132-
elif check_type_str == 'parameter':
133-
check._validate(params=evaluate_args['params'], mode=evaluate_args['mode'])
134-
elif check_type_str == 'regex':
135-
check._validate(regex=evaluate_args['regex'], mode=evaluate_args['mode'])
136-
elif check_type_str == 'operator':
137-
check._validate(params=evaluate_args)
138-
130+
if check_type_str == "tolerance":
131+
check._validate(evaluate_args.get("tolerance"))
132+
elif check_type_str == "parameter_match":
133+
check._validate(params=evaluate_args.get("params"), mode=evaluate_args.get("mode"))
134+
elif check_type_str == "regex":
135+
check._validate(regex=evaluate_args.get("regex"), mode=evaluate_args.get("mode"))
136+
elif check_type_str == "operator":
137+
check._validate(evaluate_args)
138+
139139
assert exc_info.type is ValueError and exc_info.value.args[0] == expected_results

0 commit comments

Comments
 (0)