11"""CheckType Implementation."""
2- from typing import Mapping , Iterable , Tuple , Union , List , Dict , Any
3- from .evaluator import diff_generator
4- from typing import Mapping , Tuple , Union , List , Iterable
2+ from typing import Mapping , Tuple , List , Dict , Any
53from .evaluator import diff_generator , parameter_evaluator
64from .runner import extract_values_from_output
75
@@ -30,33 +28,29 @@ def init(*args):
3028 raise NotImplementedError
3129
3230 @staticmethod
33- def extract_value_from_json_path (output : Union [ Mapping , Iterable ] , path : str , exclude : List = None ) -> Any :
31+ def get_value (output : Mapping , path : str , exclude : List = None ) -> Any :
3432 """Return the value contained into a Mapping for a defined path."""
3533 return extract_values_from_output (output , path , exclude )
3634
37- def evaluate (
38- self , reference_value : Union [Mapping , Iterable ], value_to_compare : Union [Mapping , Iterable ]
39- ) -> Tuple [Dict , bool ]:
35+ def evaluate (self , reference_value : Any , value_to_compare : Any ) -> Tuple [Dict , bool ]:
4036 """Return the result of the evaluation and a boolean True if it passes it or False otherwise.
4137
4238 This method is the one that each CheckType has to implement.
4339
4440 Args:
45- reference_value: dataset to compare
46- value_to_compare: dataset to compare
41+ reference_value: Can be any structured data or just a simple value.
42+ value_to_compare: Similar value as above to perform comparison.
4743
4844 Returns:
49- tuple: Dictionary representing differences between datasets , bool indicating if differences are found.
45+ tuple: Dictionary representing check result , bool indicating if differences are found.
5046 """
5147 raise NotImplementedError
5248
5349
5450class ExactMatchType (CheckType ):
5551 """Exact Match class docstring."""
5652
57- def evaluate (
58- self , reference_value : Union [Mapping , Iterable ], value_to_compare : Union [Mapping , Iterable ]
59- ) -> Tuple [Mapping , bool ]:
53+ def evaluate (self , reference_value : Any , value_to_compare : Any ) -> Tuple [Dict , bool ]:
6054 """Returns the difference between values and the boolean."""
6155 diff = diff_generator (reference_value , value_to_compare )
6256 return diff , not diff
@@ -75,13 +69,13 @@ def __init__(self, *args):
7569 self .tolerance_factor = float (tolerance ) / 100
7670 super ().__init__ ()
7771
78- def evaluate (self , reference_value : Mapping , value_to_compare : Mapping ) -> Tuple [Mapping , bool ]:
72+ def evaluate (self , reference_value : Mapping , value_to_compare : Mapping ) -> Tuple [Dict , bool ]:
7973 """Returns the difference between values and the boolean. Overwrites method in base class."""
8074 diff = diff_generator (reference_value , value_to_compare )
8175 diff = self ._get_outliers (diff )
8276 return diff , not diff
8377
84- def _get_outliers (self , diff : Mapping ) -> Mapping :
78+ def _get_outliers (self , diff : Mapping ) -> Dict :
8579 """Return a mapping of values outside the tolerance threshold."""
8680 result = {
8781 key : {sub_key : values for sub_key , values in obj .items () if not self ._within_tolerance (** values )}
@@ -98,7 +92,7 @@ def _within_tolerance(self, *, old_value: float, new_value: float) -> bool:
9892class ParameterMatchType (CheckType ):
9993 """Parameter Match class implementation."""
10094
101- def evaluate (self , reference_value : Mapping , value_to_compare : Mapping ) -> Tuple [Mapping , bool ]:
95+ def evaluate (self , reference_value : Mapping , value_to_compare : Mapping ) -> Tuple [Dict , bool ]:
10296 """Parameter Match evaluator implementation."""
10397 try :
10498 parameter = value_to_compare [1 ]
0 commit comments