test_Anchor_1.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 from localizer_dwm1001.msg import Anchor
8 import rosunit
9 
10 # Structure Message Anchor
11 # string id
12 # float64 x
13 # float64 y
14 # float64 z
15 # float64 distanceFromTag
16 
17 class Anchor1TestCase(unittest.TestCase):
18 
19  anchorData_ok = False
20  anchor1 = Anchor()
21 
22  def callback(self, data):
23  self.anchorData_ok = True
24  self.anchor1 = data
25 
26  # Test existance of topic
28  rospy.init_node('test_anchor_1')
29  rospy.Subscriber("/dwm1001/anchor1", Anchor, self.callback)
30  counter = 1
31  # give 5 seconds to check the topic is publishing something
32  while not rospy.is_shutdown() and counter < 5 and (not self.anchorData_ok):
33  time.sleep(1)
34  counter += 1
35  rospy.loginfo("looping")
36 
37  self.assertTrue(self.anchorData_ok)
38 
39  # Test the id of Anchor if is a string
41  if isinstance(self.anchor1.id, str):
42  self.assertTrue(True)
43  else:
44  self.assertTrue(False)
45 
46 
47  # Test the x of Anchor if is a float
49  if isinstance(self.anchor1.x, float):
50  self.assertTrue(True)
51  else:
52  self.assertTrue(False)
53 
54 
55  # Test the y of Anchor if is a float
57  if isinstance(self.anchor1.y, float):
58  self.assertTrue(True)
59  else:
60  self.assertTrue(False)
61 
62 
63  # Test the z of Anchor if is a float
65  if isinstance(self.anchor1.z, float):
66  self.assertTrue(True)
67  else:
68  self.assertTrue(False)
69 
70 
71  # Test the z of Anchor if is a float
73  if isinstance(self.anchor1.distanceFromTag, float):
74  self.assertTrue(True)
75  else:
76  self.assertTrue(False)
77 
78 
79 
80 if __name__ == '__main__':
81  rosunit.unitrun('localizer_dwm1001', 'test_Anchor_1_Publisher', Anchor1TestCase)
82 
83 
def test_if_anchor_1_distanceFromTag_is_float(self)


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