test_robot_state_exporter.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2018 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 import rospy
18 import sys
19 import os
20 import shutil
21 from sr_robot_commander.sr_robot_state_exporter import SrRobotStateExporter
22 from unittest import TestCase
23 from std_srvs.srv import SetBool
24 
25 PKG = "sr_robot_commander"
26 
27 
28 class TestSrRobotStateExporter(TestCase):
29  """
30  Tests the Robot State Exporter
31  """
32  @classmethod
33  def setUpClass(cls):
34  if not os.path.exists("/tmp/test_exporter"):
35  os.mkdir("/tmp/test_exporter")
36 
37  @classmethod
38  def tearDownClass(cls):
39  shutil.rmtree("/tmp/test_exporter", ignore_errors=True)
40 
41  def setUp(self):
42  rospy.init_node('test_hand_commander', anonymous=True)
43  self.test_path = "/tmp/test_exporter"
44  sys.path.append(self.test_path)
45  self.expected_state = {
46  'state1': {
47  'joint_test1': 1.0,
48  'joint_test2': 2.0}
49  }
50  self.expected_states = {
51  'state1': {
52  'joint_test1': 1.0,
53  'joint_test2': 2.0
54  },
55  'state2': {
56  'joint_test3': 3.0,
57  'joint_test4': 4.0
58  }
59  }
60 
61  def test_extract_all(self):
62  rospy.wait_for_service("/has_robot_state")
63  state_exporter = SrRobotStateExporter()
64  state_exporter.extract_all()
65  state_exporter.output_module(self.test_path + "/exporter_output_all.py")
66  from exporter_output_all import warehouse_states
67  self.assertEqual(warehouse_states, self.expected_states, msg="Export all states failed:" +
68  str(warehouse_states) + " not " + str(self.expected_states))
69 
71  rospy.wait_for_service("/has_robot_state")
72  state_exporter = SrRobotStateExporter()
73  state_exporter.extract_one_state("state1")
74  state_exporter.output_module(self.test_path + "/exporter_output_state.py")
75  from exporter_output_state import warehouse_states
76  self.assertEqual(warehouse_states, self.expected_state, msg="Export all states failed:" +
77  str(warehouse_states) + " not " + str(self.expected_state))
78 
79  def test_extract_list(self):
80  rospy.wait_for_service("/has_robot_state")
81  state_exporter = SrRobotStateExporter()
82  state_exporter.extract_list(["state1"])
83  state_exporter.output_module(self.test_path + "/exporter_output_list.py")
84  from exporter_output_list import warehouse_states
85  self.assertEqual(warehouse_states, self.expected_state, msg="Export all states failed:" +
86  str(warehouse_states) + " not " + str(self.expected_state))
87 
88 
89 if __name__ == "__main__":
90  import rostest
91  rostest.rosrun(PKG, "test_robot_state_exporter", TestSrRobotStateExporter)


sr_robot_commander
Author(s): Andriy Petlovanyy
autogenerated on Wed Oct 14 2020 04:05:30