Completed
Push — master ( 8c5af0...53749f )
by Wojtek
8s
created

CallsProcessFactory._create_stages()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
crap 2
1
"""Contains factory class of process with calls stages."""
2
3 1
from grortir.main.model.processes.calls_process import CallsProcess
4 1
from grortir.main.model.stages.calls_stage import CallsStage
5
6
7 1
class CallsProcessFactory:
8
    """Class which produce process with the same type of stages.
9
10
    Attributes:
11
        structure_type (str): represent type of structure
12
        how_many_nodes (int): how many nodes should be in generated process
13
        max_calls (int): max_calls for stages
14
        process (CallsProcess): process which will be incrementally build
15
    """
16
17 1
    def __init__(self, structure_type, how_many_nodes, max_calls):
18
        """Constructor."""
19 1
        self.max_calls = max_calls
20 1
        self._stages_to_add = []
21 1
        self.structure_type = structure_type
22 1
        self.how_many_nodes = how_many_nodes
23 1
        self.process = CallsProcess()
24
25 1
    def _update_structure(self):
26
        """Update structure of process."""
27 1
        if self.structure_type == "linear":
28 1
            self.process.add_path(self._stages_to_add)
29
        else:
30 1
            raise NotImplementedError()
31
32 1
    def _create_stages(self):
33
        """Create stages which will be injected to process."""
34 1
        for i in range(self.how_many_nodes):
35 1
            self._stages_to_add += [CallsStage(str(i), self.max_calls)]
36
37 1
    def construct_process(self):
38
        """Construct process."""
39 1
        self._create_stages()
40 1
        self._update_structure()
41
        return self.process
42