test_state_saver_no_hardware.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 from sr_robot_commander.sr_robot_state_saver import SrStateSaverUnsafe
19 
20 from unittest import TestCase
21 
22 PKG = "sr_robot_commander"
23 
24 
26  """
27  Tests the state saver raises exceptions when launched with no hardware present.
28  """
29 
30  def setUp(self):
31  rospy.init_node('test_state_saver_no_hardware', anonymous=True)
32 
33  def test_no_name(self):
34  exception_raised = False
35  exception_string = ''
36 
37  try:
38  state_saver = SrStateSaverUnsafe('')
39  except Exception as e:
40  exception_raised = True
41  exception_string = str(e)
42 
43  self.assertTrue(exception_raised)
44  self.assertEqual(exception_string, "Cannot save with empty name.")
45 
46  def test_with_hand(self):
47  exception_raised = False
48  exception_string = ''
49 
50  try:
51  state_saver = SrStateSaverUnsafe("test_name", "hand")
52  except Exception as e:
53  exception_raised = True
54  exception_string = str(e)
55 
56  self.assertTrue(exception_raised)
57  self.assertEqual(exception_string, "'No hand found.'")
58 
59  def test_with_arm(self):
60  exception_raised = False
61  exception_string = ''
62 
63  try:
64  state_saver = SrStateSaverUnsafe("test_name", "arm")
65  except Exception as e:
66  exception_raised = True
67  exception_string = str(e)
68 
69  self.assertTrue(exception_raised)
70  self.assertEqual(exception_string, "'No arm found.'")
71 
72  def test_with_both(self):
73  exception_raised = False
74  exception_string = ''
75 
76  try:
77  state_saver = SrStateSaverUnsafe("test_name", "both")
78  except Exception as e:
79  exception_raised = True
80  exception_string = str(e)
81 
82  self.assertTrue(exception_raised)
83  self.assertEqual(exception_string, "'No hand found.' 'No arm found.'")
84 
85 
86 if __name__ == "__main__":
87  import rostest
88  rostest.rosrun(PKG, "test_state_saver_no_hardware", TestSrStateSaverExceptions)


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