Skip to content

Commit 5465858

Browse files
committed
move validate method to private
1 parent 40b2d68 commit 5465858

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

netcompare/check_types.py

Lines changed: 11 additions & 11 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(**kwargs) -> None:
133133
"""Method to validate arguments that raises proper exceptions."""
134134

135135
@staticmethod
@@ -142,13 +142,13 @@ class ExactMatchType(CheckType):
142142
"""Exact Match class docstring."""
143143

144144
@staticmethod
145-
def validate(**kwargs) -> None:
145+
def _validate(**kwargs) -> None:
146146
"""Method to validate arguments."""
147147
# reference_data = getattr(kwargs, "reference_data")
148148

149149
def evaluate(self, value_to_compare: Any, reference_data: Any) -> Tuple[Dict, bool]:
150150
"""Returns the difference between values and the boolean."""
151-
self.validate(reference_data=reference_data)
151+
self._validate(reference_data=reference_data)
152152
evaluation_result = diff_generator(reference_data, value_to_compare)
153153
return self.result(evaluation_result)
154154

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

159159
@staticmethod
160-
def validate(**kwargs) -> None:
160+
def _validate(**kwargs) -> None:
161161
"""Method to validate arguments."""
162162
# reference_data = getattr(kwargs, "reference_data")
163163
tolerance = kwargs.get("tolerance")
@@ -170,7 +170,7 @@ def validate(**kwargs) -> None:
170170

171171
def evaluate(self, value_to_compare: Any, reference_data: Any, tolerance: int) -> Tuple[Dict, bool]:
172172
"""Returns the difference between values and the boolean. Overwrites method in base class."""
173-
self.validate(reference_data=reference_data, tolerance=tolerance)
173+
self._validate(reference_data=reference_data, tolerance=tolerance)
174174
evaluation_result = diff_generator(reference_data, value_to_compare)
175175
self._remove_within_tolerance(evaluation_result, tolerance)
176176
return self.result(evaluation_result)
@@ -206,7 +206,7 @@ class ParameterMatchType(CheckType):
206206
"""Parameter Match class implementation."""
207207

208208
@staticmethod
209-
def validate(**kwargs) -> None:
209+
def _validate(**kwargs) -> None:
210210
"""Method to validate arguments."""
211211
mode_options = ["match", "no-match"]
212212
params = kwargs.get("params")
@@ -225,7 +225,7 @@ def validate(**kwargs) -> None:
225225

226226
def evaluate(self, value_to_compare: Mapping, params: Dict, mode: str) -> Tuple[Dict, bool]:
227227
"""Parameter Match evaluator implementation."""
228-
self.validate(params=params, mode=mode)
228+
self._validate(params=params, mode=mode)
229229
# TODO: we don't use the mode?
230230
evaluation_result = parameter_evaluator(value_to_compare, params, mode)
231231
return self.result(evaluation_result)
@@ -235,7 +235,7 @@ class RegexType(CheckType):
235235
"""Regex Match class implementation."""
236236

237237
@staticmethod
238-
def validate(**kwargs) -> None:
238+
def _validate(**kwargs) -> None:
239239
"""Method to validate arguments."""
240240
mode_options = ["match", "no-match"]
241241
regex = kwargs.get("regex")
@@ -252,7 +252,7 @@ def validate(**kwargs) -> None:
252252

253253
def evaluate(self, value_to_compare: Mapping, regex: str, mode: str) -> Tuple[Mapping, bool]:
254254
"""Regex Match evaluator implementation."""
255-
self.validate(regex=regex, mode=mode)
255+
self._validate(regex=regex, mode=mode)
256256
evaluation_result = regex_evaluator(value_to_compare, regex, mode)
257257
return self.result(evaluation_result)
258258

@@ -261,7 +261,7 @@ class OperatorType(CheckType):
261261
"""Operator class implementation."""
262262

263263
@staticmethod
264-
def validate(**kwargs) -> None:
264+
def _validate(**kwargs) -> None:
265265
"""Validate operator parameters."""
266266
in_operators = ("is-in", "not-in", "in-range", "not-range")
267267
bool_operators = ("all-same",)
@@ -334,7 +334,7 @@ def validate(**kwargs) -> None:
334334

335335
def evaluate(self, value_to_compare: Any, params: Any) -> Tuple[Dict, bool]:
336336
"""Operator evaluator implementation."""
337-
self.validate(**params)
337+
self._validate(**params)
338338
# For name consistency.
339339
reference_data = params
340340
evaluation_result = operator_evaluator(reference_data["params"], value_to_compare)

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ no-docstring-rgx="^(_|test_|Meta$)"
7171
# Line length is enforced by Black, so pylint doesn't need to check it.
7272
# Pylint and Black disagree about how to format multi-line arrays; Black wins.
7373
# too-many-branches disabled to supported nested logic in Operator.
74+
# protected-access disabled as we want test the method
7475
disable = """,
7576
line-too-long,
7677
bad-continuation,
77-
too-many-branches
78+
too-many-branches,
79+
protected-access
7880
"""
7981

8082
[tool.pylint.miscellaneous]

tests/test_type_checks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CheckTypeChild(CheckType):
1515

1616
assert (
1717
"Can't instantiate abstract class CheckTypeChild"
18-
" with abstract methods evaluate, validate" in error.value.__str__()
18+
" with abstract methods _validate, evaluate" in error.value.__str__()
1919
)
2020

2121

@@ -26,14 +26,14 @@ class CheckTypeChild(CheckType):
2626
"""Test Class."""
2727

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

3232
def evaluate(self, *args, **kwargs):
3333
return {}, True
3434

3535
check = CheckTypeChild()
36-
assert isinstance(check, CheckTypeChild) and check.validate() is None and check.evaluate() == ({}, True)
36+
assert isinstance(check, CheckTypeChild) and check._validate() is None and check.evaluate() == ({}, True)
3737

3838

3939
@pytest.mark.parametrize(

tests/test_validates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ def test_tolerance_key_name(check_type_str, evaluate_args, expected_results):
127127
check = CheckType.init(check_type_str)
128128

129129
with pytest.raises(ValueError) as exc_info:
130-
check.validate(**evaluate_args)
130+
check._validate(**evaluate_args)
131131

132132
assert exc_info.type is ValueError and exc_info.value.args[0] == expected_results

0 commit comments

Comments
 (0)