1
|
|
|
"""Test class for module calls_stage.""" |
2
|
|
|
|
3
|
|
|
from unittest import TestCase |
4
|
|
|
from unittest.mock import Mock, sentinel |
5
|
|
|
|
6
|
|
|
from grortir.main.model.stages.calls_stage import CallsStage |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TestCallsStage(TestCase): |
10
|
|
|
"""Test class for CallsStage.""" |
11
|
|
|
|
12
|
|
|
def test_get_quality(self): |
13
|
|
|
"""Test for get_quality method.""" |
14
|
|
|
tested_object = Mock() |
15
|
|
|
tested_object.cost = 7 |
16
|
|
|
tested_object.calculate_quality.return_value = sentinel.quality |
17
|
|
|
result = CallsStage.get_quality(tested_object) |
18
|
|
|
self.assertEqual(tested_object.cost, 8) |
19
|
|
|
tested_object.calculate_quality.assert_called_with() |
20
|
|
|
self.assertEqual(result, sentinel.quality) |
21
|
|
|
|
22
|
|
|
def test_get_cost(self): |
23
|
|
|
"""Test for get_cost method.""" |
24
|
|
|
tested_object = Mock() |
25
|
|
|
tested_object.cost = sentinel.cost |
26
|
|
|
result = CallsStage.get_cost(tested_object) |
27
|
|
|
self.assertEqual(result, sentinel.cost) |
28
|
|
|
|
29
|
|
|
def test_calculate_quality_ex(self): |
30
|
|
|
"""Test case when control are wrong.""" |
31
|
|
|
input_vector = (2, 3, 4, 5, 6) |
32
|
|
|
tested_object = CallsStage(input_vector) |
33
|
|
|
tested_object.control_params = [2, 2] |
34
|
|
|
with self.assertRaises(AssertionError): |
35
|
|
|
tested_object.calculate_quality() |
36
|
|
|
|
37
|
|
|
def test_calculate_quality_ok(self): |
38
|
|
|
"""Test case when control params and input are ok.""" |
39
|
|
|
input_vector = (2, 3, 4, 5, 6) |
40
|
|
|
tested_object = CallsStage(input_vector) |
41
|
|
|
tested_object.control_params = [1, 1, 1, 1, 1] |
42
|
|
|
result = tested_object.calculate_quality() |
43
|
|
|
self.assertEqual(result, 55) |
44
|
|
|
|