20 from mock
import ANY, MagicMock, Mock, call, patch
21 from prbt_hardware_support.msg
import OperationModes
22 from python_qt_binding.QtCore
import QObject
24 from std_msgs.msg
import Bool, Float64
41 return [cb[1][2]
for cb
in mock.mock_calls
if cb[1][0] == topic_name][0]
44 @patch(
'rospy.Subscriber')
45 @patch(
'pilz_status_indicator_rqt.status_indicator.PilzStatusIndicatorWidget')
48 Testing the status indicator plugin to correctly interface with ROS. 52 """Initialized Plugin and test if initialization methods are called 55 psi._widget.set_ROS_status.assert_called_once_with(
False)
56 psi._widget.set_HW_status.assert_called_once_with(
False)
57 psi._widget.set_operation_mode.assert_called_once_with(
58 OperationModes.UNKNOWN)
59 psi._widget.set_speed.assert_called_once_with(0.5)
60 SubscriberMock.assert_has_calls([
61 call(TOPIC_STATE_ROS, Bool, ANY),
62 call(TOPIC_STATE_HW, Bool, ANY),
63 call(TOPIC_OPERATION_MODE, OperationModes, ANY),
64 call(TOPIC_SPEED_OVERRIDE, Float64, ANY),
68 """Test if updates to the HW status are correctly passed from ROS to 71 psi._widget.reset_mock()
74 SubscriberMock, TOPIC_STATE_HW)
76 diagnostic_prbt_callback(Bool(
False))
77 psi._widget.set_HW_status.assert_called_with(
False)
79 diagnostic_prbt_callback(Bool(
True))
80 psi._widget.set_HW_status.assert_called_with(
True)
83 """Test if updates to the ROS status are correctly passed from ROS to 86 psi._widget.reset_mock()
89 SubscriberMock, TOPIC_STATE_ROS)
91 diagnostic_ros_callback(Bool(
True))
92 psi._widget.set_ROS_status.assert_called_with(
True)
94 diagnostic_ros_callback(Bool(
False))
95 psi._widget.set_ROS_status.assert_called_with(
False)
98 """Test if updates to the operation mode are correctly passed from ROS 101 psi._widget.reset_mock()
104 SubscriberMock, TOPIC_OPERATION_MODE)
106 operation_mode_msg = OperationModes()
108 operation_mode_msg.value = OperationModes.UNKNOWN
109 diagnostic_operation_mode_callback(operation_mode_msg)
110 psi._widget.set_operation_mode.assert_called_with(
111 OperationModes.UNKNOWN)
113 operation_mode_msg.value = OperationModes.T1
114 diagnostic_operation_mode_callback(operation_mode_msg)
115 psi._widget.set_operation_mode.assert_called_with(OperationModes.T1)
117 operation_mode_msg.value = OperationModes.T2
118 diagnostic_operation_mode_callback(operation_mode_msg)
119 psi._widget.set_operation_mode.assert_called_with(OperationModes.T2)
121 operation_mode_msg.value = OperationModes.AUTO
122 diagnostic_operation_mode_callback(operation_mode_msg)
123 psi._widget.set_operation_mode.assert_called_with(OperationModes.AUTO)
126 """Test if updates to the speed override are correctly passed from ROS 129 psi._widget.reset_mock()
132 SubscriberMock, TOPIC_SPEED_OVERRIDE)
134 speed_msg = Float64()
137 speed_callback(speed_msg)
138 psi._widget.set_speed.assert_called_with(0)
141 speed_callback(speed_msg)
142 psi._widget.set_speed.assert_called_with(0.5)
145 speed_callback(speed_msg)
146 psi._widget.set_speed.assert_called_with(1.0)
149 if __name__ ==
'__main__':
151 rosunit.unitrun(
'pilz_status_indicator_rqt',
152 'test_status_indicator', TestStatusIndicator)
def add_widget(arg1, arg2)
def test_set_speed(self, _, SubscriberMock)
def extract_subscriber_mock_callback(mock, topic_name)
def test_status_ros(self, _, SubscriberMock)
def test_operation_mode(self, _, SubscriberMock)
def test_status_prbt(self, _, SubscriberMock)
def test_init(self, _, SubscriberMock)