test_save_mesh_server.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import unittest
4 
5 import rospy
6 import rostest
7 from std_srvs.srv import Empty
8 
9 from jsk_recognition_msgs.msg import BoundingBox
10 from jsk_recognition_msgs.srv import SaveMesh
11 from jsk_recognition_msgs.srv import SaveMeshResponse
12 
13 
15 
16  def __init__(self):
17  self.pub = rospy.Publisher('~bbox_output', BoundingBox, queue_size=1)
18  rospy.sleep(0.1)
19  rospy.Timer(rospy.Duration(0.1), self._cb)
20 
21  def _cb(self, event):
22  self.box = BoundingBox()
23  self.box.header.stamp = event.current_real
24  self.box.header.frame_id = 'dummy_frame'
25  self.box.pose.position.x = 1.0
26  self.box.pose.position.y = 2.0
27  self.box.pose.position.z = 3.0
28  self.box.pose.orientation.x = 4.0
29  self.box.pose.orientation.y = 5.0
30  self.box.pose.orientation.z = 6.0
31  self.box.pose.orientation.w = 7.0
32  self.box.dimensions.x = 8.0
33  self.box.dimensions.y = 9.0
34  self.box.dimensions.z = 10.0
35  self.box.value = 11.0
36  self.box.label = 12
37  self.pub.publish(self.box)
38 
39 
41 
42  def __init__(self):
43  rospy.Timer(rospy.Duration(1.0), self._cb)
44 
45  def _cb(self, event):
46  rospy.wait_for_service('~request')
47  req_caller = rospy.ServiceProxy('~request', Empty)
48  self.res = req_caller()
49 
50 
51 class TestSaveMeshServer(unittest.TestCase):
52 
56  self.cb_tested = False
57  self.srv_server = rospy.Service('~save_mesh', SaveMesh, self._cb)
58  while self.cb_tested is False:
59  rospy.sleep(0.1)
60  self.assertTrue(self.cb_tested is True)
61 
62  def _cb(self, req):
63  # Check if ground_frame_id parameter and that of request are the same.
64  assert rospy.get_param('~ground_frame_id') == req.ground_frame_id
65 
66  # Check if published bbox and that of request are the same.
67  assert self.bbox_publisher.box == req.box
68 
69  self.cb_tested = True
70  return SaveMeshResponse(True)
71 
72 
73 if __name__ == '__main__':
74  rospy.init_node('test_save_mesh_server')
75  rostest.rosrun(
76  'jsk_recognition_msgs', 'test_save_mesh_server', TestSaveMeshServer)


jsk_recognition_msgs
Author(s):
autogenerated on Mon May 3 2021 03:02:56