diff --git a/nav2_util/test/CMakeLists.txt b/nav2_util/test/CMakeLists.txt index dff0a3bb1e523cad43fe7c7070cfeb9ab4d9e201..4d3b5511dc8ebb63b96890dd33c22c85bbeb2520 100644 --- a/nav2_util/test/CMakeLists.txt +++ b/nav2_util/test/CMakeLists.txt @@ -44,10 +44,34 @@ target_link_libraries(test_robot_utils ${library_name}) # This test is disabled due to failing services # https://github.com/ros-planning/navigation2/issues/1836 -# add_launch_test( -# "test_dump_params/test_dump_params.test.py" -# TARGET "test_dump_params" -# TIMEOUT 30 -# ENV -# TEST_EXECUTABLE=$<TARGET_FILE:dump_params> -# ) +add_launch_test( + "test_dump_params/test_dump_params_default.test.py" + TARGET "test_dump_params_default" + TIMEOUT 10 + ENV + TEST_EXECUTABLE=$<TARGET_FILE:dump_params> +) + +add_launch_test( + "test_dump_params/test_dump_params_yaml.test.py" + TARGET "test_dump_params_yaml" + TIMEOUT 10 + ENV + TEST_EXECUTABLE=$<TARGET_FILE:dump_params> +) + +add_launch_test( + "test_dump_params/test_dump_params_md.test.py" + TARGET "test_dump_params_md" + TIMEOUT 10 + ENV + TEST_EXECUTABLE=$<TARGET_FILE:dump_params> +) + +add_launch_test( + "test_dump_params/test_dump_params_multiple.test.py" + TARGET "test_dump_params_multiple" + TIMEOUT 10 + ENV + TEST_EXECUTABLE=$<TARGET_FILE:dump_params> +) diff --git a/nav2_util/test/test_dump_params/test_dump_params.test.py b/nav2_util/test/test_dump_params/test_dump_params_default.test.py similarity index 68% rename from nav2_util/test/test_dump_params/test_dump_params.test.py rename to nav2_util/test/test_dump_params/test_dump_params_default.test.py index 55d28b5fac4107b09a4f8acabbbea23e9694b91b..e0849b398fbd33f141b34f83d7fae8f77b952d8b 100644 --- a/nav2_util/test/test_dump_params/test_dump_params.test.py +++ b/nav2_util/test/test_dump_params/test_dump_params_default.test.py @@ -37,12 +37,6 @@ def generate_test_description(): cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')], name='test_dump_params') ) - launch_description.add_action( - ExecuteProcess( - cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py'), - 'test_dump_params_copy'], - name='test_dump_params_copy') - ) processes_to_test = [ ExecuteProcess( cmd=[os.getenv('TEST_EXECUTABLE'), '-h'], @@ -52,30 +46,6 @@ def generate_test_description(): cmd=[os.getenv('TEST_EXECUTABLE')], name='test_dump_params_default', output='screen'), - ExecuteProcess( - cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params'], - name='test_dump_params_yaml', - output='screen'), - ExecuteProcess( - cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params'], - name='test_dump_params_markdown', - output='screen'), - ExecuteProcess( - cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params', '-v'], - name='test_dump_params_yaml_verbose', - output='screen'), - ExecuteProcess( - cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params', '-v'], - name='test_dump_params_markdown_verbose', - output='screen'), - ExecuteProcess( - cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'error', '-n', 'test_dump_params'], - name='test_dump_params_bad_format', - output='screen'), - ExecuteProcess( - cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params,test_dump_params_copy'], - name='test_dump_params_multiple', - output='screen'), ExecuteProcess( cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params_error'], name='test_dump_params_error', @@ -114,12 +84,6 @@ class TestDumpParams(unittest.TestCase): os.path.join(os.path.dirname(__file__), out) for out in ['dump_params_help', 'dump_params_default', - 'dump_params_yaml', - 'dump_params_md', - 'dump_params_yaml_verbose', - 'dump_params_md_verbose', - 'dump_params_yaml', - 'dump_params_multiple', 'dump_params_error'] ] for process, output_file in zip(processes_to_test[:-1], output_files[:-1]): diff --git a/nav2_util/test/test_dump_params/test_dump_params_md.test.py b/nav2_util/test/test_dump_params/test_dump_params_md.test.py new file mode 100644 index 0000000000000000000000000000000000000000..61a85c514cdf2a8d43fae0807804ffa484b1b1bd --- /dev/null +++ b/nav2_util/test/test_dump_params/test_dump_params_md.test.py @@ -0,0 +1,90 @@ +#! /usr/bin/env python3 +# Copyright (c) 2020 Sarthak Mittal +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import unittest + +from launch import LaunchDescription +from launch.actions import ExecuteProcess + +import launch_testing +import launch_testing.actions +import launch_testing.asserts +import launch_testing.util +import launch_testing_ros + +import pytest + + +@pytest.mark.launch_test +def generate_test_description(): + launch_description = LaunchDescription() + launch_description.add_action( + ExecuteProcess( + cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')], + name='test_dump_params') + ) + processes_to_test = [ + ExecuteProcess( + cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params'], + name='test_dump_params_markdown', + output='screen'), + ExecuteProcess( + cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params', '-v'], + name='test_dump_params_markdown_verbose', + output='screen') + ] + for process in processes_to_test: + launch_description.add_action(process) + launch_description.add_action( + launch_testing.actions.ReadyToTest() + ) + return launch_description, {'processes_to_test': processes_to_test} + + +# Tests without a unittest to run concurrently with +# the processes under test throw an exception +# The following is a dummy test to suppress the traceback +# https://github.com/ros2/launch/issues/380 + +class TestLoggingOutputFormat(unittest.TestCase): + + def test_logging_output(self, proc_info, processes_to_test): + for process_name in processes_to_test: + proc_info.assertWaitForShutdown(process=process_name, timeout=10) + + +@launch_testing.post_shutdown_test() +class TestDumpParams(unittest.TestCase): + + def test_processes_output(self, proc_output, processes_to_test): + """Test all processes output against expectations.""" + from launch_testing.tools.output import get_default_filtered_prefixes + output_filter = launch_testing_ros.tools.basic_output_filter( + filtered_prefixes=get_default_filtered_prefixes() + ) + output_files = [ + os.path.join(os.path.dirname(__file__), out) + for out in ['dump_params_md', + 'dump_params_md_verbose'] + ] + for process, output_file in zip(processes_to_test, output_files): + launch_testing.asserts.assertInStdout( + proc_output, + expected_output=launch_testing.tools.expected_output_from_file( + path=output_file), + process=process, output_filter=output_filter + ) diff --git a/nav2_util/test/test_dump_params/test_dump_params_multiple.test.py b/nav2_util/test/test_dump_params/test_dump_params_multiple.test.py new file mode 100644 index 0000000000000000000000000000000000000000..4733c19f5846ef1bf3441ab57c254be7fbe20e8e --- /dev/null +++ b/nav2_util/test/test_dump_params/test_dump_params_multiple.test.py @@ -0,0 +1,96 @@ +#! /usr/bin/env python3 +# Copyright (c) 2020 Sarthak Mittal +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import unittest + +from launch import LaunchDescription +from launch.actions import ExecuteProcess + +import launch_testing +import launch_testing.actions +import launch_testing.asserts +import launch_testing.util +import launch_testing_ros + +import pytest + + +@pytest.mark.launch_test +def generate_test_description(): + launch_description = LaunchDescription() + launch_description.add_action( + ExecuteProcess( + cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')], + name='test_dump_params') + ) + launch_description.add_action( + ExecuteProcess( + cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py'), + 'test_dump_params_copy'], + name='test_dump_params_copy') + ) + processes_to_test = [ + ExecuteProcess( + cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'error', '-n', 'test_dump_params'], + name='test_dump_params_bad_format', + output='screen'), + ExecuteProcess( + cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params,test_dump_params_copy'], + name='test_dump_params_multiple', + output='screen') + ] + for process in processes_to_test: + launch_description.add_action(process) + launch_description.add_action( + launch_testing.actions.ReadyToTest() + ) + return launch_description, {'processes_to_test': processes_to_test} + + +# Tests without a unittest to run concurrently with +# the processes under test throw an exception +# The following is a dummy test to suppress the traceback +# https://github.com/ros2/launch/issues/380 + +class TestLoggingOutputFormat(unittest.TestCase): + + def test_logging_output(self, proc_info, processes_to_test): + for process_name in processes_to_test: + proc_info.assertWaitForShutdown(process=process_name, timeout=10) + + +@launch_testing.post_shutdown_test() +class TestDumpParams(unittest.TestCase): + + def test_processes_output(self, proc_output, processes_to_test): + """Test all processes output against expectations.""" + from launch_testing.tools.output import get_default_filtered_prefixes + output_filter = launch_testing_ros.tools.basic_output_filter( + filtered_prefixes=get_default_filtered_prefixes() + ) + output_files = [ + os.path.join(os.path.dirname(__file__), out) + for out in ['dump_params_yaml', + 'dump_params_multiple'] + ] + for process, output_file in zip(processes_to_test[:-1], output_files[:-1]): + launch_testing.asserts.assertInStdout( + proc_output, + expected_output=launch_testing.tools.expected_output_from_file( + path=output_file), + process=process, output_filter=output_filter + ) diff --git a/nav2_util/test/test_dump_params/test_dump_params_yaml.test.py b/nav2_util/test/test_dump_params/test_dump_params_yaml.test.py new file mode 100644 index 0000000000000000000000000000000000000000..545bf4934cf645760bf8e97274d5af52805e2e5f --- /dev/null +++ b/nav2_util/test/test_dump_params/test_dump_params_yaml.test.py @@ -0,0 +1,90 @@ +#! /usr/bin/env python3 +# Copyright (c) 2020 Sarthak Mittal +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import unittest + +from launch import LaunchDescription +from launch.actions import ExecuteProcess + +import launch_testing +import launch_testing.actions +import launch_testing.asserts +import launch_testing.util +import launch_testing_ros + +import pytest + + +@pytest.mark.launch_test +def generate_test_description(): + launch_description = LaunchDescription() + launch_description.add_action( + ExecuteProcess( + cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')], + name='test_dump_params') + ) + processes_to_test = [ + ExecuteProcess( + cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params'], + name='test_dump_params_yaml', + output='screen'), + ExecuteProcess( + cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params', '-v'], + name='test_dump_params_yaml_verbose', + output='screen') + ] + for process in processes_to_test: + launch_description.add_action(process) + launch_description.add_action( + launch_testing.actions.ReadyToTest() + ) + return launch_description, {'processes_to_test': processes_to_test} + + +# Tests without a unittest to run concurrently with +# the processes under test throw an exception +# The following is a dummy test to suppress the traceback +# https://github.com/ros2/launch/issues/380 + +class TestLoggingOutputFormat(unittest.TestCase): + + def test_logging_output(self, proc_info, processes_to_test): + for process_name in processes_to_test: + proc_info.assertWaitForShutdown(process=process_name, timeout=10) + + +@launch_testing.post_shutdown_test() +class TestDumpParams(unittest.TestCase): + + def test_processes_output(self, proc_output, processes_to_test): + """Test all processes output against expectations.""" + from launch_testing.tools.output import get_default_filtered_prefixes + output_filter = launch_testing_ros.tools.basic_output_filter( + filtered_prefixes=get_default_filtered_prefixes() + ) + output_files = [ + os.path.join(os.path.dirname(__file__), out) + for out in ['dump_params_yaml', + 'dump_params_yaml_verbose'] + ] + for process, output_file in zip(processes_to_test, output_files): + launch_testing.asserts.assertInStdout( + proc_output, + expected_output=launch_testing.tools.expected_output_from_file( + path=output_file), + process=process, output_filter=output_filter + )