test_handlight.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2014, Tokyo Opensource Robotics Kyokai Association
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Author: Isaac I.Y. Saito
37 
38 import unittest
39 
40 import rostest
41 
42 from nextage_ros_bridge import nextage_client
43 
44 _GOINITIAL_TIME_MIDSPEED = 3 # second
45 _PKG = 'nextage_ros_bridge'
46 
47 
48 class TestNxoHandlight(unittest.TestCase):
49  '''
50  Test NextageClient with rostest. This does NOT test hardware (i.e. if DIO
51  is connected and functioning); instead, this only verifies if the
52  software works as to the given hardware spec.
53 
54  For tests involving hardware, follow
55  https://github.com/start-jsk/rtmros_hironx/issues/272.
56  '''
57 
58  @classmethod
59  def setUpClass(cls):
60  cls._robot = nextage_client.NextageClient() # Latest (v0.5 or newer)
61  cls._robot.init()
62  cls._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
63 
64  # For older DIO version robot.
65  cls._robot_04 = nextage_client.NextageClient()
66  cls._robot_04.set_hand_version(version=cls._robot_04.HAND_VER_0_4_2)
67  cls._robot_04.init()
68  cls._robot_04.goInitial(_GOINITIAL_TIME_MIDSPEED)
69 
70  @classmethod
71  def tearDownClass(cls):
72  cls._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
73  cls._robot_04.goInitial(_GOINITIAL_TIME_MIDSPEED)
74 
75  # On simulator, return of DIO methods should fail no matter what
76  # argument is passed. So assertFalse doesn't do much...it works
77  # to verify that the tested methods "run without error".
78 
80  '''Testing software version 0.5 or newer'''
81  if self._robot.simulation_mode:
82  result = self._robot._hands.handlight_r(is_on=False)
83  self.assertTrue(result)
84  else:
85  result = self._robot._hands.handlight_r(is_on=True)
86  self.assertTrue(result)
87 
89  if self._robot.simulation_mode:
90  result = self._robot_04.handlight_r(is_on=False)
91  self.assertTrue(result)
92  else:
93  result = self._robot_04.handlight_r(is_on=True)
94  self.assertTrue(result)
95 
97  '''Testing software version 0.5 or newer'''
98  if self._robot.simulation_mode:
99  result = self._robot._hands.handlight_l(is_on=False)
100  self.assertFalse(result)
101  else:
102  result = self._robot._hands.handlight_l(is_on=True)
103  self.assertTrue(result)
104 
106  if self._robot.simulation_mode:
107  result = self._robot_04.handlight_l(is_on=False)
108  self.assertTrue(result)
109  else:
110  result = self._robot_04.handlight_l(is_on=True)
111  self.assertTrue(result)
112 
114  '''Testing software version 0.5 or newer'''
115  if self._robot.simulation_mode:
116  # Check if checking false works.
117  result = self._robot._hands.handlight_both(is_on=False)
118  self.assertFalse(result)
119  else:
120  result = self._robot._hands.handlight_both(is_on=True)
121  self.assertTrue(result)
122 
124  if self._robot.simulation_mode:
125  # Check if checking false works.
126  result = self._robot_04.handlight_both(is_on=False) and result
127  self.assertFalse(result)
128  else:
129  result = self._robot_04.handlight_both(is_on=True) and result
130  self.assertTrue(result)
131 
132 if __name__ == '__main__':
133  rostest.rosrun(_PKG, 'test_nxo_handlight', TestNxoHandlight)


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47