|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Copyright 2024 PickNik Inc. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# * Redistributions of source code must retain the above copyright |
| 9 | +# notice, this list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# * Redistributions in binary form must reproduce the above copyright |
| 12 | +# notice, this list of conditions and the following disclaimer in the |
| 13 | +# documentation and/or other materials provided with the distribution. |
| 14 | +# |
| 15 | +# * Neither the name of the s nor the names of its |
| 16 | +# contributors may be used to endorse or promote products derived from |
| 17 | +# this software without specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | +# POSSIBILITY OF SUCH DAMAGE. |
| 30 | + |
| 31 | + |
| 32 | +import os |
| 33 | +import unittest |
| 34 | +from pathlib import Path |
| 35 | + |
| 36 | +import launch_testing |
| 37 | +from launch import LaunchDescription |
| 38 | +from launch.actions import ( |
| 39 | + DeclareLaunchArgument, |
| 40 | + IncludeLaunchDescription, |
| 41 | + TimerAction, |
| 42 | +) |
| 43 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 44 | +from launch.substitutions import ( |
| 45 | + LaunchConfiguration, |
| 46 | + PathJoinSubstitution, |
| 47 | +) |
| 48 | +from launch_ros.actions import Node |
| 49 | + |
| 50 | +SCRIPT_PATH = Path(os.path.realpath(__file__)).parent |
| 51 | + |
| 52 | + |
| 53 | +def generate_test_description(): |
| 54 | + test_node = Node( |
| 55 | + executable=LaunchConfiguration("test_file"), |
| 56 | + ) |
| 57 | + |
| 58 | + return LaunchDescription( |
| 59 | + [ |
| 60 | + IncludeLaunchDescription( |
| 61 | + PythonLaunchDescriptionSource( |
| 62 | + [ |
| 63 | + PathJoinSubstitution( |
| 64 | + [ |
| 65 | + str(SCRIPT_PATH), |
| 66 | + "control.launch.py", |
| 67 | + ], |
| 68 | + ), |
| 69 | + ], |
| 70 | + ), |
| 71 | + ), |
| 72 | + DeclareLaunchArgument("test_file"), |
| 73 | + TimerAction(period=2.0, actions=[test_node]), |
| 74 | + launch_testing.util.KeepAliveProc(), |
| 75 | + launch_testing.actions.ReadyToTest(), |
| 76 | + ], |
| 77 | + ), { |
| 78 | + "test_node": test_node, |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | +class TestWaitForCompletion(unittest.TestCase): |
| 83 | + # Waits for test to complete, then waits a bit to make sure result files are generated |
| 84 | + def test_run_complete(self, test_node): |
| 85 | + self.proc_info.assertWaitForShutdown(test_node, timeout=4000.0) |
| 86 | + |
| 87 | + |
| 88 | +@launch_testing.post_shutdown_test() |
| 89 | +class TestProcessPostShutdown(unittest.TestCase): |
| 90 | + # Checks if the test has been completed with acceptable exit codes (successful codes) |
| 91 | + def test_pass(self, proc_info, test_node): |
| 92 | + launch_testing.asserts.assertExitCodes(proc_info, process=test_node) |
0 commit comments