Skip to content

Commit

Permalink
Fix dump params tests (#1886)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Mittal <sarthakmittal2608@gmail.com>
  • Loading branch information
naiveHobo authored Jul 23, 2020
1 parent 0fcbd7c commit c65e3aa
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 43 deletions.
38 changes: 31 additions & 7 deletions nav2_util/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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',
Expand Down Expand Up @@ -114,12 +84,6 @@ def test_processes_output(self, proc_output, processes_to_test):
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]):
Expand Down
90 changes: 90 additions & 0 deletions nav2_util/test/test_dump_params/test_dump_params_md.test.py
Original file line number Diff line number Diff line change
@@ -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
)
96 changes: 96 additions & 0 deletions nav2_util/test/test_dump_params/test_dump_params_multiple.test.py
Original file line number Diff line number Diff line change
@@ -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
)
90 changes: 90 additions & 0 deletions nav2_util/test/test_dump_params/test_dump_params_yaml.test.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit c65e3aa

Please sign in to comment.