File size: 2,185 Bytes
6fffc74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from copy import deepcopy
from typing import Optional, Any, List, Dict

from flows import utils
from flows.base_flows.abstract import AtomicFlow

log = utils.get_pylogger(__name__)


class CodeTesting(AtomicFlow):
    REQUIRED_KEYS_CONFIG = []
    REQUIRED_KEYS_KWARGS = []

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def _get_test_data(self, input_data: Dict):
        """This function retrieves (or generates) input-output pairs that will be used to test the implementation."""
        raise NotImplementedError()

    def _run_tests(self, input_data: Dict, test_data: Dict) -> Dict[str, Any]:
        raise NotImplementedError()

    @classmethod
    def instantiate_from_config(cls, config):
        flow_config = deepcopy(config)

        kwargs = {"flow_config": flow_config}
        kwargs["input_data_transformations"] = cls._set_up_data_transformations(config["input_data_transformations"])
        kwargs["output_data_transformations"] = cls._set_up_data_transformations(config["output_data_transformations"])

        # ~~~ Instantiate flow ~~~
        return cls(**kwargs)

    def run(self,
            input_data: Dict[str, Any],
            private_keys: Optional[List[str]] = [],
            keys_to_ignore_for_hash: Optional[List[str]] = []) -> Dict[str, Any]:

        # ~~~ Retrieve the test data ~~~
        test_data = self._get_test_data(input_data)

        # ~~~ Run tests ~~~
        response = self._run_tests(input_data, test_data)

        return response

# from typing import Optional, Any, List, Dict
#
# from flows.base_flows.abstract import AtomicFlow
# from flows.utils.general_helpers import validate_parameters
#
# class CodeTester(AtomicFlow):
#     REQUIRED_KEYS_CONFIG = []
#     REQUIRED_KEYS_KWARGS = []
#
#     def __init__(self, **kwargs):
#         super().__init__(**kwargs)
#
#     @classmethod
#     def _validate_parameters(cls, kwargs):
#         validate_parameters(cls, kwargs)  # is this necessary?
#
#     def run(self,
#             input_data: Dict[str, Any],
#             private_keys: Optional[List[str]] = [],
#             keys_to_ignore_for_hash: Optional[List[str]] = []) -> Dict[str, Any]: