def test_testheader_passthrough(self): # 20 seconds to validate fixture timeout_t = time.time() + 20. print "waiting for 20 seconds for fixture to verify" while self.fixture_curr is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(timeout_t < time.time(), "timeout exceeded") self.failIf(rospy.is_shutdown(), "node shutdown") self.failIf(self.fixture_curr is None, "no data from fixture") self.assertEquals('/node0', self.fixture_curr.caller_id) self.assertEquals('', self.fixture_curr.orig_caller_id) # another 20 seconds to validate client timeout_t = time.time() + 20. print "waiting for 20 seconds for client to verify" while self.test_curr is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(self.test_curr is None, "no data from test") self.assertEquals('/rosjava_node', self.test_curr.caller_id) self.assertEquals('/node0', self.test_curr.orig_caller_id) t = self.test_curr.header.stamp.to_sec() # be really generous here, just need to be in the ballpark. self.assert_(abs(time.time() - t) < 60.)
def test_composite_passthrough(self): # 20 seconds to validate fixture timeout_t = time.time() + 20. print("waiting for 20 seconds for fixture to verify") while self.fixture_curr is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.assertFalse(timeout_t < time.time(), "timeout exceeded") self.assertFalse(rospy.is_shutdown(), "node shutdown") self.assertFalse(self.fixture_curr is None, "no data from fixture") m = self.fixture_curr self.assertAlmostEqual(m.a.x, m.b.x) self.assertAlmostEqual(m.a.y, m.b.y) self.assertAlmostEqual(m.a.z, m.b.z) # another 20 seconds to validate client timeout_t = time.time() + 20. print("waiting for 20 seconds for client to verify") while self.test_curr is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.assertFalse(self.test_curr is None, "no data from test") m = self.test_curr self.assertAlmostEqual(m.a.x, m.b.x) self.assertAlmostEqual(m.a.y, m.b.y) self.assertAlmostEqual(m.a.z, m.b.z) # a.w = a.x + a.y + a.z. Just make sure we're in the ballpark a = self.test_curr.a self.assertTrue(abs(a.x + a.y + a.z - a.w) < 10.)
def test_int64_passthrough(self): # 20 seconds to validate fixture timeout_t = time.time() + 20. print "waiting for 20 seconds for fixture to verify" while self.fixture_prev is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(timeout_t < time.time(), "timeout exceeded") self.failIf(rospy.is_shutdown(), "node shutdown") self.failIf(self.fixture_prev is None, "no data from fixture") self.failIf(self.fixture_curr is None, "no data from fixture") self.assertEquals(self.fixture_prev.data + 1, self.fixture_curr.data, "fixture should incr by one") # another 20 seconds to validate client timeout_t = time.time() + 20. print "waiting for 20 seconds for client to verify" while self.test_prev is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(self.test_prev is None, "no data from test") self.assertEquals(self.test_prev.data + 1, self.test_curr.data, "test does not appear to match fixture data")
def test_string_passthrough(self): # 20 seconds to validate fixture timeout_t = time.time() + 20. print "waiting for 20 seconds for fixture to verify" while not self.fixture_nodes_cb == self.nodes_set and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(timeout_t < time.time(), "timeout exceeded") self.failIf(rospy.is_shutdown(), "node shutdown") self.assertEquals(self.nodes_set, self.fixture_nodes_cb, "fixture did not validate: %s vs %s"%(self.nodes_set, self.fixture_nodes_cb)) # another 20 seconds to validate client timeout_t = time.time() + 20. print "waiting for 20 seconds for client to verify" while not self.test_nodes_cb == self.nodes_set and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.assertEquals(self.nodes_set, self.test_nodes_cb, "passthrough did not pass along all message") # Create a new Publisher here. This will validate publisherUpdate() pub = rospy.Publisher('string_in', String) msg = 'test_publisherUpdate' timeout_t = time.time() + 20. print "waiting for 20 seconds for client to verify" while not msg in self.nodes_set and \ not rospy.is_shutdown() and \ timeout_t > time.time(): pub.publish(data=msg) time.sleep(0.2)
def test_composite_passthrough(self): # 20 seconds to validate fixture timeout_t = time.time() + 20. print "waiting for 20 seconds for fixture to verify" while self.fixture_curr is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(timeout_t < time.time(), "timeout exceeded") self.failIf(rospy.is_shutdown(), "node shutdown") self.failIf(self.fixture_curr is None, "no data from fixture") m = self.fixture_curr self.assertAlmostEquals(m.a.x, m.b.x) self.assertAlmostEquals(m.a.y, m.b.y) self.assertAlmostEquals(m.a.z, m.b.z) # another 20 seconds to validate client timeout_t = time.time() + 20. print "waiting for 20 seconds for client to verify" while self.test_curr is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(self.test_curr is None, "no data from test") m = self.test_curr self.assertAlmostEquals(m.a.x, m.b.x) self.assertAlmostEquals(m.a.y, m.b.y) self.assertAlmostEquals(m.a.z, m.b.z) # a.w = a.x + a.y + a.z. Just make sure we're in the ballpark a = self.test_curr.a self.assert_(abs(a.x + a.y + a.z - a.w) < 10.)
def test_int64_passthrough(self): # 20 seconds to validate fixture timeout_t = time.time() + 20. print("waiting for 20 seconds for fixture to verify") while self.fixture_prev is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.assertFalse(timeout_t < time.time(), "timeout exceeded") self.assertFalse(rospy.is_shutdown(), "node shutdown") self.assertFalse(self.fixture_prev is None, "no data from fixture") self.assertFalse(self.fixture_curr is None, "no data from fixture") self.assertEqual(self.fixture_prev.data + 1, self.fixture_curr.data, "fixture should incr by one") # another 20 seconds to validate client timeout_t = time.time() + 20. print("waiting for 20 seconds for client to verify") while self.test_prev is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.assertFalse(self.test_prev is None, "no data from test") self.assertEqual(self.test_prev.data + 1, self.test_curr.data, "test does not appear to match fixture data")
def test_tilde_parameter(self): timeout_t = time.time() + 20. print "waiting for 20 seconds for client to load" while self.tilde_msg is None and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) self.failIf(timeout_t < time.time(), "timeout exceeded") self.failIf(rospy.is_shutdown(), "node shutdown") self.failIf(self.tilde_msg is None) self.assertEquals(rospy.get_param('param_client/tilde'), self.tilde_msg.data)
def publisher(): rospy.init_node('string_publisher') pub = rospy.Publisher('string_in', std_msgs.msg.String) m = std_msgs.msg.String(rospy.get_name()) r = rospy.Rate(10) while not rospy.is_shutdown(): pub.publish(m) r.sleep()
def test_parameter_client_read(self): timeout_t = time.time() + 20. print("waiting for 20 seconds for client to load") tests = self.tests msgs = [None] while any(1 for m in msgs if m is None) and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) msgs = [getattr(self, t + '_msg') for t in tests] print("msgs: %s" % (msgs)) self.assertFalse(timeout_t < time.time(), "timeout exceeded") self.assertFalse(rospy.is_shutdown(), "node shutdown") self.assertFalse(any(1 for m in msgs if m is None), "did not receive all expected messages: " + str(msgs)) ns = rospy.get_param('parameter_namespace') for t in tests: p_name = roslib.names.ns_join(ns, t) value = rospy.get_param(p_name, t) msg = getattr(self, "%s_msg" % (t)) print("get param: %s" % (p_name)) print("param value: %s" % (value)) print("msg value: %s" % (msg)) if t == 'composite': print("value", p_name, value) m = Composite(CompositeA(**value['a']), CompositeB(**value['b'])) self.assertAlmostEqual(m.a.x, msg.a.x) self.assertAlmostEqual(m.a.y, msg.a.y) self.assertAlmostEqual(m.a.z, msg.a.z) self.assertAlmostEqual(m.a.w, msg.a.w) self.assertAlmostEqual(m.b.x, msg.b.x) self.assertAlmostEqual(m.b.y, msg.b.y) self.assertAlmostEqual(m.b.z, msg.b.z) elif t == 'list': self.assertEqual(list(value), list(msg.int32_array)) elif t == 'float': self.assertAlmostEqual(value, msg.data) else: self.assertEqual(value, msg.data)
def publisher(): rospy.init_node('testheader_publisher') pub = rospy.Publisher('test_header_in', rosjava_test_msgs.msg.TestHeader) r = rospy.Rate(10) m = rosjava_test_msgs.msg.TestHeader() m.caller_id = rospy.get_name() m.header.stamp = rospy.get_rostime() while not rospy.is_shutdown(): pub.publish(m) r.sleep()
def test_parameter_client_read(self): timeout_t = time.time() + 20. print "waiting for 20 seconds for client to load" tests = self.tests msgs = [None] while any(1 for m in msgs if m is None) and \ not rospy.is_shutdown() and \ timeout_t > time.time(): time.sleep(0.2) msgs = [getattr(self, t+'_msg') for t in tests] print "msgs: %s"%(msgs) self.failIf(timeout_t < time.time(), "timeout exceeded") self.failIf(rospy.is_shutdown(), "node shutdown") self.failIf(any(1 for m in msgs if m is None), "did not receive all expected messages: "+str(msgs)) ns = rospy.get_param('parameter_namespace') for t in tests: p_name = roslib.names.ns_join(ns, t) value = rospy.get_param(p_name, t) msg = getattr(self, "%s_msg"%(t)) print "get param: %s"%(p_name) print "param value: %s"%(value) print "msg value: %s"%(msg) if t == 'composite': print "value", p_name, value m = Composite(CompositeA(**value['a']), CompositeB(**value['b'])) self.assertAlmostEquals(m.a.x, msg.a.x) self.assertAlmostEquals(m.a.y, msg.a.y) self.assertAlmostEquals(m.a.z, msg.a.z) self.assertAlmostEquals(m.a.w, msg.a.w) self.assertAlmostEquals(m.b.x, msg.b.x) self.assertAlmostEquals(m.b.y, msg.b.y) self.assertAlmostEquals(m.b.z, msg.b.z) elif t == 'list': self.assertEquals(list(value), list(msg.int32_array)) elif t == 'float': self.assertAlmostEquals(value, msg.data) else: self.assertEquals(value, msg.data)
def publisher(): rospy.init_node('int64_publisher') pub = rospy.Publisher('int64_in', std_msgs.msg.Int64) i = 0 r = rospy.Rate(10) m = std_msgs.msg.Int64(i) while not rospy.is_shutdown(): pub.publish(m) i += 1 m.data = i r.sleep()
def publisher(): rospy.init_node('composite_publisher') pub = rospy.Publisher('composite_in', test_ros.msg.Composite) r = rospy.Rate(10) m = test_ros.msg.Composite() m.a.x = random.random() * 10000. m.a.y = random.random() * 10000. m.a.z = random.random() * 10000. m.a.w = m.a.x + m.a.y + m.a.z m.b.x = m.a.x m.b.y = m.a.y m.b.z = m.a.z while not rospy.is_shutdown(): pub.publish(m) r.sleep()