Completed
Pull Request — master (#43)
by Wojtek
09:32
created

TestGroupedOptimizer.test___init__()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
1
"""Module for testing grouped optimizer."""
2
3
from unittest import TestCase
4
from unittest.mock import Mock
5
6
from grortir.main.model.core.abstract_process import AbstractProcess
7
from grortir.main.model.core.abstract_stage import AbstractStage
8
from grortir.main.optimizers.grouped_optimizer import GroupedOptimizer
9
10
11
class TestGroupedOptimizer(TestCase):
12
    """Class for testing Optimizer."""
13
14
    def setUp(self):
15
        """Set up environment."""
16
        self.some_process = AbstractProcess()
17
        self.first_stage = AbstractStage()
18
        self.second_stage = AbstractStage()
19
        self.third_stage_a = Mock()
20
        self.third_stage_b = Mock()
21
        self.some_process.add_path([self.first_stage, self.second_stage,
0 ignored issues
show
Bug introduced by
The Instance of AbstractProcess does not seem to have a member named add_path.

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...
22
                                    self.third_stage_a])
23
        self.some_process.add_edge(self.second_stage, self.third_stage_b)
0 ignored issues
show
Bug introduced by
The Instance of AbstractProcess does not seem to have a member named add_edge.

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...
24
25
    def test___init__(self):
26
        """Testing creating object."""
27
        optimizer = GroupedOptimizer(self.some_process, Mock())
28
        self.assertIsNotNone(optimizer)
29
        self.assertEqual(optimizer.process, self.some_process)
30
31
    def test_calling_functions(self):
32
        """Test correct order of calling function."""
33
        optimizer = GroupedOptimizer(self.some_process, Mock())
34
        optimizer.optimize_process()
35
36
37
class DeterministicStage(AbstractStage):
0 ignored issues
show
Coding Style introduced by
This class 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...
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
38
    def __init__(self, max_get_output_of_stage_count=10,
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
39
                 max_is_enough_quality_count=10,
40
                 max_could_be_optimized_count=10, max_get_quality_count=10,
41
                 max_get_cost_count=10):
42
        super().__init__((0, 0, 0, 0))
43
        self.get_cost_count = 0
44
        self.get_quality_count = 0
45
        self.could_be_optimized_count = 0
46
        self.is_enough_quality_count = 0
47
        self.get_output_of_stage_count = 0
48
        self.max_get_cost_count = max_get_cost_count
49
        self.max_get_quality_count = max_get_quality_count
50
        self.max_could_be_optimized_count = max_could_be_optimized_count
51
        self.max_is_enough_quality_count = max_is_enough_quality_count
52
        self.max_get_output_of_stage_count = max_get_output_of_stage_count
53
54
    def get_cost(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'get_cost' method
Loading history...
55
        self.get_cost_count += 1
56
57
    def get_quality(self, control_params=None):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'get_quality' method
Loading history...
58
        self.get_quality_count += 1
59
        return
60
61
    def could_be_optimized(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'could_be_optimized' method
Loading history...
62
        self.could_be_optimized_count += 1
63
        return True
64
65
    def is_enough_quality(self, value):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'is_enough_quality' method
Loading history...
66
        self.is_enough_quality_count += 1
67
        return self.is_enough_quality_count == value
68
69
    def get_output_of_stage(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'get_output_of_stage' method
Loading history...
70
        self.get_output_of_stage_count += 1
71
        return [self.get_output_of_stage_count] * len(self.input_vector)
72
73