|
| 1 | +# Copyright (c) 2024 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Redistribution and use in source and binary forms, with or without |
| 4 | +# modification, are permitted provided that the following conditions are met: |
| 5 | +# |
| 6 | +# * Redistributions of source code must retain the above copyright |
| 7 | +# notice, this list of conditions and the following disclaimer. |
| 8 | +# |
| 9 | +# * Redistributions in binary form must reproduce the above copyright |
| 10 | +# notice, this list of conditions and the following disclaimer in the |
| 11 | +# documentation and/or other materials provided with the distribution. |
| 12 | +# |
| 13 | +# * Neither the name of the copyright holder nor the names of its |
| 14 | +# contributors may be used to endorse or promote products derived from |
| 15 | +# this software without specific prior written permission. |
| 16 | +# |
| 17 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 21 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | +# POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +import os |
| 30 | +import unittest |
| 31 | + |
| 32 | +import launch |
| 33 | +from launch import LaunchDescription |
| 34 | +from launch_ros.actions import Node |
| 35 | +import launch_testing |
| 36 | +import launch_testing.actions |
| 37 | +import launch_testing.asserts |
| 38 | + |
| 39 | + |
| 40 | +def generate_test_description(): |
| 41 | + test_exe_arg = launch.actions.DeclareLaunchArgument( |
| 42 | + 'test_exe', |
| 43 | + description='Path to executable test', |
| 44 | + ) |
| 45 | + |
| 46 | + process_under_test = launch.actions.ExecuteProcess( |
| 47 | + cmd=[launch.substitutions.LaunchConfiguration('test_exe')], |
| 48 | + output='screen', |
| 49 | + ) |
| 50 | + |
| 51 | + urdf_file = os.path.join(os.path.dirname(__file__), 'mimic_joint.urdf') |
| 52 | + with open(urdf_file, 'r') as infp: |
| 53 | + robot_desc = infp.read() |
| 54 | + |
| 55 | + params = {'robot_description': robot_desc} |
| 56 | + node_robot_state_publisher = Node( |
| 57 | + package='robot_state_publisher', |
| 58 | + executable='robot_state_publisher', |
| 59 | + output='screen', |
| 60 | + parameters=[params] |
| 61 | + ) |
| 62 | + |
| 63 | + return LaunchDescription([ |
| 64 | + node_robot_state_publisher, |
| 65 | + test_exe_arg, |
| 66 | + process_under_test, |
| 67 | + launch_testing.util.KeepAliveProc(), |
| 68 | + launch_testing.actions.ReadyToTest(), |
| 69 | + ]), locals() |
| 70 | + |
| 71 | + |
| 72 | +class TestChangeFixedJoint(unittest.TestCase): |
| 73 | + |
| 74 | + def test_termination(self, process_under_test, proc_info): |
| 75 | + proc_info.assertWaitForShutdown(process=process_under_test, timeout=(10)) |
| 76 | + |
| 77 | + |
| 78 | +@launch_testing.post_shutdown_test() |
| 79 | +class ChangeFixedJointTestAfterShutdown(unittest.TestCase): |
| 80 | + |
| 81 | + def test_exit_code(self, process_under_test, proc_info): |
| 82 | + # Check that all processes in the launch (in this case, there's just one) exit |
| 83 | + # with code 0 |
| 84 | + launch_testing.asserts.assertExitCodes( |
| 85 | + proc_info, |
| 86 | + [launch_testing.asserts.EXIT_OK], |
| 87 | + process_under_test |
| 88 | + ) |
0 commit comments