66from netcompare .arguments import (
77 CheckArguments ,
88 CheckArgumentsExactMatch ,
9- CheckArgumentsParameterMatch ,
109 CheckArgumentsRegexMatch ,
10+ CheckArgumentsParameterMatch ,
1111 CheckArgumentsToleranceMatch ,
1212)
1313
2020)
2121from .utils .data_normalization import exclude_filter , flatten_list
2222from .evaluators import diff_generator , parameter_evaluator , regex_evaluator
23- from .check_types import *
23+
24+ # pylint: disable=arguments-differ
2425
2526
2627class CheckType :
2728 """Check Type Class."""
2829
2930 class_args = CheckArguments
3031
31- def __init__ (self , * args ):
32- """Check Type init method."""
33-
3432 @staticmethod
3533 def init (check_type ):
3634 """Factory pattern to get the appropriate CheckType implementation.
3735
3836 Args:
39- *args: Variable length argument list .
37+ check_type: String to define the type of check .
4038 """
4139 if check_type == "exact_match" :
4240 return ExactMatchType ()
@@ -99,58 +97,42 @@ def get_value(output: Union[Mapping, List], path: str, exclude: List = None) ->
9997
10098 return values
10199
102- def hook_evaluate (self , reference_value : CheckArguments , value_to_compare : Any ) -> Tuple [Dict , bool ]:
100+ def evaluate (self , value_to_compare : Any , ** kwargs ) -> Tuple [Dict , bool ]:
103101 """Return the result of the evaluation and a boolean True if it passes it or False otherwise.
104102
105103 This method is the one that each CheckType has to implement.
106104
107105 Args:
108- reference_value: Can be any structured data or just a simple value.
109106 value_to_compare: Similar value as above to perform comparison.
110107
111108 Returns:
112109 tuple: Dictionary representing check result, bool indicating if differences are found.
113110 """
114111 raise NotImplementedError
115112
116- def evaluate (self , reference_value : dict , value_to_compare : Any ) -> Tuple [Dict , bool ]:
117-
118- return self .hook_evaluate (self .args_class (reference_value ), value_to_compare )
119-
120113
121114class ExactMatchType (CheckType ):
122115 """Exact Match class docstring."""
123116
124- args_class = CheckArgumentsExactMatch
117+ validator_class = CheckArgumentsExactMatch
125118
126- def evaluate (self , reference_value : CheckArgumentsExactMatch , value_to_compare : Any ) -> Tuple [Dict , bool ]:
119+ def evaluate (self , value_to_compare : Any , reference_data : Any ) -> Tuple [Dict , bool ]:
127120 """Returns the difference between values and the boolean."""
128- evaluation_result = diff_generator (reference_value .reference_data , value_to_compare )
121+ self .validator_class .validate (reference_data = reference_data )
122+ evaluation_result = diff_generator (reference_data , value_to_compare )
129123 return evaluation_result , not evaluation_result
130124
131125
132126class ToleranceType (CheckType ):
133127 """Tolerance class docstring."""
134128
135- def __init__ (self , * args ):
136- """Tolerance init method."""
137- super ().__init__ ()
129+ validator_class = CheckArgumentsToleranceMatch
138130
139- try :
140- tolerance = float (args [1 ])
141- except IndexError as error :
142- raise IndexError (f"Tolerance parameter must be defined as float at index 1. You have: { args } " ) from error
143- except ValueError as error :
144- raise ValueError (f"Argument must be convertible to float. You have: { args [1 ]} " ) from error
145-
146- self .tolerance_factor = tolerance / 100
147-
148- def hook_evaluate (
149- self , reference_value : CheckArgumentsToleranceMatch , value_to_compare : Mapping
150- ) -> Tuple [Dict , bool ]:
131+ def evaluate (self , value_to_compare : Any , reference_data : Any , tolerance : int ) -> Tuple [Dict , bool ]:
151132 """Returns the difference between values and the boolean. Overwrites method in base class."""
152- diff = diff_generator (reference_value .reference_data , value_to_compare )
153- self ._remove_within_tolerance (diff , reference_value .tolerance )
133+ self .validator_class .validate (reference_data = reference_data , tolerance = tolerance )
134+ diff = diff_generator (reference_data , value_to_compare )
135+ self ._remove_within_tolerance (diff , tolerance )
154136 return diff , not diff
155137
156138 def _remove_within_tolerance (self , diff : Dict , tolerance : int ) -> None :
@@ -174,41 +156,23 @@ def _within_tolerance(*, old_value: float, new_value: float) -> bool:
174156class ParameterMatchType (CheckType ):
175157 """Parameter Match class implementation."""
176158
177- def hook_evaluate (
178- self , reference_value : CheckArgumentsParameterMatch , value_to_compare : Mapping
179- ) -> Tuple [Dict , bool ]:
180- """Parameter Match evaluator implementation."""
181- if not isinstance (value_to_compare , dict ):
182- raise TypeError ("check_option must be of type dict()" )
159+ validator_class = CheckArgumentsParameterMatch
183160
184- # TODO: update this
185- evaluation_result = parameter_evaluator (reference_value , value_to_compare )
161+ def evaluate (self , value_to_compare : Mapping , params : Dict , mode : str ) -> Tuple [Dict , bool ]:
162+ """Parameter Match evaluator implementation."""
163+ self .validator_class .validate (params = params , mode = mode )
164+ # TODO: we don't use the mode?
165+ evaluation_result = parameter_evaluator (value_to_compare , params )
186166 return evaluation_result , not evaluation_result
187167
188168
189169class RegexType (CheckType ):
190170 """Regex Match class implementation."""
191171
192- def hook_evaluate (
193- self , reference_value : CheckArgumentsRegexMatch , value_to_compare : Mapping
194- ) -> Tuple [Mapping , bool ]:
172+ validator_class = CheckArgumentsRegexMatch
173+
174+ def evaluate ( self , value_to_compare : Mapping , regex : str , mode : str ) -> Tuple [Mapping , bool ]:
195175 """Regex Match evaluator implementation."""
196- # Check that check value_to_compare is dict.
197- if not isinstance (value_to_compare , dict ):
198- raise TypeError ("check_option must be of type dict()." )
199-
200- # Check that value_to_compare has 'regex' and 'mode' dict keys.
201- if any (key not in value_to_compare .keys () for key in ("regex" , "mode" )):
202- raise KeyError (
203- "Regex check-type requires check-option. Example: dict(regex='.*UNDERLAY.*', mode='no-match')."
204- )
205-
206- # Assert that check option has 'regex' and 'mode' dict keys.\
207- if value_to_compare ["mode" ] not in ["match" , "no-match" ]:
208- raise ValueError (
209- "Regex check-type requires check-option. Example: dict(regex='.*UNDERLAY.*', mode='no-match')."
210- )
211-
212- # TODO: update this
213- diff = regex_evaluator (reference_value , value_to_compare )
176+ self .validator_class .validate (regex = regex , mode = mode )
177+ diff = regex_evaluator (value_to_compare , regex , mode )
214178 return diff , not diff
0 commit comments