travis_test_buzzer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #encoding: utf8
3 import rospy, unittest, rostest, actionlib
4 import rosnode
5 import time
6 from std_msgs.msg import UInt16
7 from raspicat.msg import MusicAction, MusicResult, MusicFeedback, MusicGoal #1行追加
8 
9 class BuzzerTest(unittest.TestCase):
10  def setUp(self): #setUpメソッドを追加する
11  self.client = actionlib.SimpleActionClient("music", MusicAction)
12  self.device_values = []
13 
14  def test_node_exist(self):
15  nodes = rosnode.get_node_names()
16  self.assertIn('/buzzer',nodes, "node does not exist")
17 
18  def test_put_value(self):
19  pub = rospy.Publisher('/buzzer', UInt16)
20  for i in range(10):
21  pub.publish(1234)
22  time.sleep(0.1)
23 
24  with open("/dev/rtbuzzer0","r") as f:
25  data = f.readline()
26  self.assertEqual(data,"1234\n","value does not written to rtbuzzer0")
27 
28  def test_music(self):
29  ### skip this test because a problem of this test code ###
30  return
31  goal = MusicGoal()
32  goal.freqs = [100, 200, 300, 0]
33  goal.durations = [2,2,2,2]
34 
35  self.client.wait_for_server()
36  self.client.send_goal(goal,feedback_cb=self.feedback_cb)
37  self.client.wait_for_result()
38 
39  self.assertTrue(self.client.get_result(),"invalid result")
40  self.assertEqual(goal.freqs,self.device_values,"invalid feedback:"
41  + ",".join([str(e) for e in self.device_values]))
42 
43  ###preemption###
44  self.device_values = []
45  self.client.send_goal(goal,feedback_cb=self.feedback_cb)
46  self.client.wait_for_result(rospy.Duration.from_sec(0.5))
47 
48  self.assertFalse(self.client.get_result(),"stop is requested but return true")
49  self.assertFalse(goal.freqs == self.device_values,"not stopped")
50 
51  def feedback_cb(self,feedback):
52  with open("/dev/rtbuzzer0","r") as f:
53  data = f.readline()
54  self.device_values.append(int(data.rstrip()))
55 
56 if __name__ == '__main__':
57  time.sleep(3)
58  rospy.init_node('travis_test_buzzer')
59  rostest.rosrun('raspicat','travis_test_buzzer',BuzzerTest)
device_values
skip this test because a problem of this test code ###


raspicat
Author(s): Ryuichi Ueda , Daisuke Sato
autogenerated on Mon Jun 10 2019 14:27:50