test_Anchor_0.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from time import sleep
4 import unittest
5 import time
6 import rospy
7 import rostest
8 from localizer_dwm1001.msg import Anchor
9 from localizer_dwm1001.msg import Tag
10 import rosunit
11 
12 # Structure Message Anchor
13 # string id
14 # float64 x
15 # float64 y
16 # float64 z
17 # float64 distanceFromTag
18 
19 class Anchor0TestCase(unittest.TestCase):
20 
21  anchorData_ok = False
22  anchor0 = Anchor()
23 
24  def callback(self, data):
25  self.anchorData_ok = True
26  self.anchor0 = data
27 
28  # Test existance of topic
30  rospy.init_node('test_anchor_0')
31  rospy.Subscriber("/dwm1001/anchor0", Anchor, self.callback)
32  counter = 0
33  # give 5 seconds to check the topic is publishing something
34  while not rospy.is_shutdown() and counter < 5 and (not self.anchorData_ok):
35  time.sleep(1)
36  counter += 1
37  rospy.loginfo("looping")
38 
39  self.assertTrue(self.anchorData_ok)
40 
41  # Test the id of Anchor if is a string
43  if isinstance(self.anchor0.id, str):
44  self.assertTrue(True)
45  else:
46  self.assertTrue(False)
47 
48 
49  # Test the x of Anchor if is a float
51  if isinstance(self.anchor0.x, float):
52  self.assertTrue(True)
53  else:
54  self.assertTrue(False)
55 
56 
57  # Test the y of Anchor if is a float
59  if isinstance(self.anchor0.y, float):
60  self.assertTrue(True)
61  else:
62  self.assertTrue(False)
63 
64 
65  # Test the z of Anchor if is a float
67  if isinstance(self.anchor0.z, float):
68  self.assertTrue(True)
69  else:
70  self.assertTrue(False)
71 
72 
73  # Test the z of Anchor if is a float
75  if isinstance(self.anchor0.distanceFromTag, float):
76  self.assertTrue(True)
77  else:
78  self.assertTrue(False)
79 
80 
81 
82 
83 
84 if __name__ == '__main__':
85  rosunit.unitrun('localizer_dwm1001', 'test_Anchor_0_Publisher', Anchor0TestCase)
86 
87 
def test_if_anchor_0_distanceFromTag_is_float(self)


dwm1001_ros
Author(s):
autogenerated on Mon Jun 10 2019 13:05:20