Completed
Push — master ( 40c094...b6a1c4 )
by Wojtek
02:30
created

CallsProcessFactory._update_structure()   A

Complexity

Conditions 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 0
loc 9
rs 9.6666
ccs 5
cts 6
cp 0.8333
crap 3.0416
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
        initial_vec (tuple): initial vector
16
    """
17
18 1
    def __init__(self, structure_type, how_many_nodes, max_calls,
19
                 initial_vec=()):
20
        """Constructor."""
21 1
        self.max_calls = max_calls
22 1
        self._stages_to_add = []
23 1
        self.structure_type = structure_type
24 1
        self.how_many_nodes = how_many_nodes
25 1
        self.process = CallsProcess()
26 1
        self.initial_vec = initial_vec
27
28 1
    def _update_structure(self):
29
        """Update structure of process."""
30 1
        if self.structure_type == "linear":
31 1
            if len(self._stages_to_add) > 1:
32 1
                self.process.add_path(self._stages_to_add)
33
            else:
34
                self.process.add_node(self._stages_to_add[0])
0 ignored issues
show
Bug introduced by
The Instance of CallsProcess does not seem to have a member named add_node.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
35
        else:
36 1
            raise NotImplementedError()
37
38 1
    def _create_stages(self):
39
        """Create stages which will be injected to process."""
40 1
        for i in range(self.how_many_nodes):
41 1
            self._stages_to_add += [
42
                CallsStage(str(i), self.max_calls, self.initial_vec)]
43
44 1
    def construct_process(self):
45
        """Construct process."""
46 1
        self._create_stages()
47 1
        self._update_structure()
48
        return self.process
49