-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_phone_button.py
More file actions
106 lines (83 loc) · 3.26 KB
/
test_phone_button.py
File metadata and controls
106 lines (83 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import unittest
from unittest.mock import patch
from mirte_robot import phone
from std_msgs.msg import Bool
import rospy
class TestPhoneButton(unittest.TestCase):
@patch('rospy.has_param')
def test_initialize_with_empty_config(self, hasParamMock):
# arange
def has_param_side_effect(value):
return False
hasParamMock.side_effect = has_param_side_effect
# act
phoneAPI = phone.createPhone()
# assert
self.assertFalse(hasattr(phoneAPI, "phone_button_subscribers"))
@patch('rospy.get_param')
@patch('rospy.has_param')
def test_initialize_with_single_item_config(self, hasParamMock, getParamMock):
# arange
def has_param_side_effect(value):
return value == "/mirte/phone_button"
# dictionary containing single phone_image_ouput instance
def get_param_side_effect(value):
return {
"button_a": {
"name": "button_a",
}
}
hasParamMock.side_effect = has_param_side_effect
getParamMock.side_effect = get_param_side_effect
# act
phoneAPI = phone.createPhone()
# assert
self.assertTrue(hasattr(phoneAPI, "phone_button_subscribers"))
self.assertNotEqual(phoneAPI.phone_button_subscribers.get("button_a"), None)
@patch('rospy.get_param')
@patch('rospy.has_param')
def test_initialize_with_multi_item_config(self, hasParamMock, getParamMock):
# arange
def has_param_side_effect(value):
return value == "/mirte/phone_button"
# dictionary containing single phone_image_ouput instance
def get_param_side_effect(value):
return {
"button_a": {
"name": "output_a",
},
"button_b": {
"name": "output_b",
}
}
hasParamMock.side_effect = has_param_side_effect
getParamMock.side_effect = get_param_side_effect
# act
phoneAPI = phone.createPhone()
# assert
self.assertTrue(hasattr(phoneAPI, "phone_button_subscribers"))
self.assertNotEqual(phoneAPI.phone_button_subscribers.get("button_a"), None)
self.assertNotEqual(phoneAPI.phone_button_subscribers.get("button_b"), None)
@patch('rospy.get_param')
@patch('rospy.has_param')
def test_get_correct_button_value(self, hasParamMock, getParamMock):
# arange
def has_param_side_effect(value):
return value == "/mirte/phone_button"
# dictionary containing single phone_image_ouput instance
def get_param_side_effect(value):
return {
"button_a": {
"name": "button_a",
}
}
hasParamMock.side_effect = has_param_side_effect
getParamMock.side_effect = get_param_side_effect
msg = Bool()
msg.data = True
# act
phoneAPI = phone.createPhone()
button_subscriber = phoneAPI.phone_button_subscribers.get("button_a")
button_subscriber.callback(msg)
# assert
self.assertEqual(phoneAPI.getButtonValue("button_a"), msg.data)