test_topic_compare.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import os
3 import sys
4 
5 import unittest
6 
7 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..",
8  "scripts")))
9 from topic_compare import ROSTopicCompare
10 
11 import rospy
12 import time
13 
14 
15 def eps_equal(a, b, err=0.001):
16  return abs(a - b) < err
17 
18 
19 class TestTopicCompare(unittest.TestCase):
20  """Subscribing three topics
21  * /origin
22  * /origin (the same topic)
23  * /half
24  """
25 
26  def test_same_topic(self):
27  while not tc.isAllTopicAvailable(20):
28  rospy.sleep(1)
29  print tc.getTotalBytes(0) / (tc.getEndTime(0) - tc.getStartTime(0))
30  print tc.getTotalBytes(1) / (tc.getEndTime(1) - tc.getStartTime(1))
31  self.assertTrue(eps_equal(tc.getBandwidth(0), tc.getBandwidth(1), 20))
32 
33  def test_half_topic(self):
34  while not tc.isAllTopicAvailable(20):
35  rospy.sleep(1)
36  print tc.getTotalBytes(0) / (tc.getEndTime(0) - tc.getStartTime(0))
37  print tc.getTotalBytes(2) / (tc.getEndTime(2) - tc.getStartTime(2))
38  self.assertTrue(eps_equal(tc.getBandwidth(0), 2 * tc.getBandwidth(2), 20))
39 
40 
41 if __name__ == "__main__":
42  import rostest
43  rospy.init_node("test_topic_compare")
45  tc.registerTopic("/origin")
46  tc.registerTopic("/origin")
47  tc.registerTopic("/half")
48  rostest.rosrun("jsk_topic_tools", "test_topic_compare", TestTopicCompare)
def eps_equal(a, b, err=0.001)


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:19