Completed
Push — master ( aa0ea9...358d48 )
by Wojtek
02:19
created

InputValidator.validate_input()   B

Complexity

Conditions 5

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 21
rs 8.439
1
"""Validator for input."""
2
from grortir.main.model.core.abstract_stage import AbstractStage
3
from tests.framework.calls.calls_registry import CallsRegistry
4
5
6
class InputValidator:
7
    """
8
        Attributes:
9
            calls_registry (CallsRegistry): calls registry
10
    """
11
12
    def __init__(self, calls_registry: CallsRegistry):
13
        """
14
15
        Args:
16
            calls_registry (CallsRegistry): registry of calls
17
        """
18
        self.calls_registry = calls_registry
19
20
    def validate_input(self, grouping_strategy, process):
21
        """
22
        Validate if input in stage successors are the same as output in stage.
23
24
        Args:
25
            grouping_strategy (GroupingStrategy): grouping strategy
26
            process (AbstractProcess): validated process
27
        Returns:
28
            bool: True if inputs are valid
29
        """
30
        all_stages = process.nodes()
31
        for stage in all_stages:
32
            groupies = grouping_strategy.get_items_from_the_same_group(stage)
33
            for successor in process.successors(stage):
34
                if successor in groupies:
35
                    result = self._validate_for_groupies(stage, successor)
36
                else:
37
                    result = self._validate_for_non_groupies(stage, successor)
38
                if result is False:
39
                    return False
40
        return True
41
42
    def _validate_for_groupies(self, stage, successor):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
43
        stage_outputs = self.calls_registry. \
44
            get_method_calls(stage.name, "get_output_of_stage")
45
        successor_inputs = self.calls_registry. \
46
            get_method_calls(successor.name, "get_quality")
47
        output_values = []
48
        inputs = []
49
        for stage_output in stage_outputs:
50
            output_values.append(stage_output['call'].output)
51
52
        for successor_input in successor_inputs:
53
            inputs.append(successor_input['call'].input_parms_list[0])
54
        print("aa")
55
        return output_values == inputs
56
57
    def _validate_for_non_groupies(self, stage: AbstractStage, successor):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
58
        stage_outputs = self.calls_registry. \
59
            get_method_calls(stage.name, "get_output_of_stage")
60
        successor_inputs = self.calls_registry. \
61
            get_method_calls(successor.name, "get_quality")
62
        print("bb")
63
        if len(stage_outputs) == 0:
64
            return len(successor_inputs) == 0
65
        else:
66
            last_output = stage_outputs[-1]['call'].output
67
            first_input = successor_inputs[0]['call'].input_parms_list[0]
68
            return last_output == first_input
69