speak-test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from __future__ import print_function
00004 
00005 import unittest
00006 
00007 import rospy
00008 from sound_play.msg import SoundRequest
00009 
00010 PKG = 'pr2eus'
00011 NAME = 'test_speack'
00012 
00013 class TestSpeak(unittest.TestCase):
00014 
00015     speak_msg = None
00016     speak_msg_jp = None
00017 
00018     def cb(self, msg):
00019         rospy.logwarn("received speak_msg")
00020         self.speak_msg = msg
00021 
00022     def cb_jp(self, msg):
00023         rospy.logwarn("received speak_msg_jp")        
00024         self.speak_msg_jp = msg
00025 
00026     def setUp(self):
00027         rospy.init_node(NAME)
00028         rospy.Subscriber('/robotsound', SoundRequest, self.cb)
00029         rospy.Subscriber('/robotsound_jp', SoundRequest, self.cb_jp)
00030 
00031     def test_speak(self):
00032         rospy.sleep(10)
00033         rospy.logwarn(self.speak_msg)
00034         rospy.logwarn(self.speak_msg_jp)
00035         while self.speak_msg == None:
00036             rospy.logwarn("waiting for speak_msg")
00037             rospy.sleep(1)
00038         rospy.logwarn("check speak_msg")
00039         self.assertTrue(self.speak_msg.command == SoundRequest.PLAY_ONCE)
00040         if hasattr(SoundRequest, 'volume'): # volume is added from 0.3.0 https://github.com/ros-drivers/audio_common/commit/da9623414f381642e52f59701c09928c72a54be7#diff-fe2d85580f1ccfed4e23a608df44a7f7
00041             self.assertTrue(self.speak_msg.volume > 0)
00042         self.assertTrue(len(self.speak_msg.arg) > 0)
00043         
00044         while self.speak_msg_jp == None:
00045             rospy.logwarn("waiting for speak_msg_jp")
00046             rospy.sleep(1)
00047         rospy.logwarn("check speak_msg")
00048         self.assertTrue(self.speak_msg_jp.command == SoundRequest.PLAY_ONCE)
00049         if hasattr(SoundRequest, 'volume'):
00050             self.assertTrue(self.speak_msg_jp.volume > 0)
00051         self.assertTrue(len(self.speak_msg_jp.arg) > 0)
00052 
00053 if __name__ == '__main__':
00054     import rostest
00055     rostest.rosrun(PKG, NAME, TestSpeak)


pr2eus
Author(s): Kei Okada
autogenerated on Thu Jun 6 2019 21:51:47