def test_rosservicewrapper_call(self, service_proxy_mock):
        client = ROSCLEClient.ROSCLEClient(0)

        # When everything is fine, the service should just be called
        service_wrapper = ROSCLEClient.ROSCLEServiceWrapper(
            'service_name', Empty, client)
        self.assertEqual(client, service_wrapper.ros_cle_client)
        service_wrapper()
        self.assertEquals(service_wrapper.handler.call_count, 1)

        # When something's wrong during the service call it should throw ROSCLEClientException
        service_wrapper = ROSCLEClient.ROSCLEServiceWrapper(
            'service_name', Empty, client, invalidate_on_failure=False)
        service_wrapper.handler.side_effect = rospy.ServiceException()

        self.assertRaises(ROSCLEClient.ROSCLEClientException, service_wrapper)

        service_wrapper.handler.side_effect = rospy.exceptions.ROSInterruptException(
        )

        self.assertRaises(ROSCLEClient.ROSCLEClientException, service_wrapper)

        # and invalidate the ROSCLEClient if asked to
        service_wrapper = ROSCLEClient.ROSCLEServiceWrapper(
            'service_name', Empty, client, invalidate_on_failure=True)
        self.assertRaises(ROSCLEClient.ROSCLEClientException, service_wrapper)
Beispiel #2
0
    def test_rosservicewrapper_constructor(self, service_proxy_mock):
        # Case when the service is correctly subscribed
        service_wrapper = ROSCLEClient.ROSCLEServiceWrapper('service_name', Empty, None)
        self.assertEquals('service_name', service_proxy_mock.call_args[0][0])
        self.assertIsInstance(service_proxy_mock.call_args[0][1], type(Empty))
        args, kwargs = service_wrapper.handler.wait_for_service.call_args_list[0]
        self.assertEquals(kwargs['timeout'], ROSCLEClient.ROSCLEServiceWrapper.ROS_SERVICE_TIMEOUT)

        # Case when the service timeouts
        service_proxy_mock.side_effect = rospy.ROSException()
        self.assertRaises(ROSCLEClient.ROSCLEClientException,
            ROSCLEClient.ROSCLEServiceWrapper, 'service_name', Empty, None)