test_Tag.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 Tag
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 TagTestCase(unittest.TestCase):
18 
19  tagData_ok = False
20  tag = Tag()
21 
22  def callback(self, data):
23  self.tagData_ok = True
24  self.tag = data
25 
26  # Test existance of topic
28  rospy.init_node('test_tag')
29  rospy.Subscriber("/dwm1001/tag", Tag, 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.tagData_ok):
33  time.sleep(1)
34  counter += 1
35  rospy.loginfo("looping")
36 
37  self.assertTrue(self.tagData_ok)
38 
39 
40  # Test the x of tag if is a float
42  if isinstance(self.tag.x, float):
43  self.assertTrue(True)
44  else:
45  self.assertTrue(False)
46 
47 
48  # Test the y of tag if is a float
50  if isinstance(self.tag.y, float):
51  self.assertTrue(True)
52  else:
53  self.assertTrue(False)
54 
55 
56  # Test the z of tag if is a float
58  if isinstance(self.tag.z, float):
59  self.assertTrue(True)
60  else:
61  self.assertTrue(False)
62 
63 
64 
65 if __name__ == '__main__':
66  rosunit.unitrun('localizer_dwm1001', 'test_Tag_3_Publisher', TagTestCase)
67 
68 
def test_if_anchor_3_is_published(self)
Definition: test_Tag.py:27
def callback(self, data)
Definition: test_Tag.py:22
def test_if_tag_z_is_float(self)
Definition: test_Tag.py:57
def test_if_tag_y_is_float(self)
Definition: test_Tag.py:49
def test_if_tag_x_is_float(self)
Definition: test_Tag.py:41


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