Skip to content

Commit c65e3aa

Browse files
authored
Fix dump params tests (#1886)
Signed-off-by: Sarthak Mittal <sarthakmittal2608@gmail.com>
1 parent 0fcbd7c commit c65e3aa

File tree

5 files changed

+307
-43
lines changed

5 files changed

+307
-43
lines changed

nav2_util/test/CMakeLists.txt

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,34 @@ target_link_libraries(test_robot_utils ${library_name})
4444
# This test is disabled due to failing services
4545
# https://github.com/ros-planning/navigation2/issues/1836
4646

47-
# add_launch_test(
48-
# "test_dump_params/test_dump_params.test.py"
49-
# TARGET "test_dump_params"
50-
# TIMEOUT 30
51-
# ENV
52-
# TEST_EXECUTABLE=$<TARGET_FILE:dump_params>
53-
# )
47+
add_launch_test(
48+
"test_dump_params/test_dump_params_default.test.py"
49+
TARGET "test_dump_params_default"
50+
TIMEOUT 10
51+
ENV
52+
TEST_EXECUTABLE=$<TARGET_FILE:dump_params>
53+
)
54+
55+
add_launch_test(
56+
"test_dump_params/test_dump_params_yaml.test.py"
57+
TARGET "test_dump_params_yaml"
58+
TIMEOUT 10
59+
ENV
60+
TEST_EXECUTABLE=$<TARGET_FILE:dump_params>
61+
)
62+
63+
add_launch_test(
64+
"test_dump_params/test_dump_params_md.test.py"
65+
TARGET "test_dump_params_md"
66+
TIMEOUT 10
67+
ENV
68+
TEST_EXECUTABLE=$<TARGET_FILE:dump_params>
69+
)
70+
71+
add_launch_test(
72+
"test_dump_params/test_dump_params_multiple.test.py"
73+
TARGET "test_dump_params_multiple"
74+
TIMEOUT 10
75+
ENV
76+
TEST_EXECUTABLE=$<TARGET_FILE:dump_params>
77+
)

nav2_util/test/test_dump_params/test_dump_params.test.py renamed to nav2_util/test/test_dump_params/test_dump_params_default.test.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ def generate_test_description():
3737
cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')],
3838
name='test_dump_params')
3939
)
40-
launch_description.add_action(
41-
ExecuteProcess(
42-
cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py'),
43-
'test_dump_params_copy'],
44-
name='test_dump_params_copy')
45-
)
4640
processes_to_test = [
4741
ExecuteProcess(
4842
cmd=[os.getenv('TEST_EXECUTABLE'), '-h'],
@@ -52,30 +46,6 @@ def generate_test_description():
5246
cmd=[os.getenv('TEST_EXECUTABLE')],
5347
name='test_dump_params_default',
5448
output='screen'),
55-
ExecuteProcess(
56-
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params'],
57-
name='test_dump_params_yaml',
58-
output='screen'),
59-
ExecuteProcess(
60-
cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params'],
61-
name='test_dump_params_markdown',
62-
output='screen'),
63-
ExecuteProcess(
64-
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params', '-v'],
65-
name='test_dump_params_yaml_verbose',
66-
output='screen'),
67-
ExecuteProcess(
68-
cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params', '-v'],
69-
name='test_dump_params_markdown_verbose',
70-
output='screen'),
71-
ExecuteProcess(
72-
cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'error', '-n', 'test_dump_params'],
73-
name='test_dump_params_bad_format',
74-
output='screen'),
75-
ExecuteProcess(
76-
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params,test_dump_params_copy'],
77-
name='test_dump_params_multiple',
78-
output='screen'),
7949
ExecuteProcess(
8050
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params_error'],
8151
name='test_dump_params_error',
@@ -114,12 +84,6 @@ def test_processes_output(self, proc_output, processes_to_test):
11484
os.path.join(os.path.dirname(__file__), out)
11585
for out in ['dump_params_help',
11686
'dump_params_default',
117-
'dump_params_yaml',
118-
'dump_params_md',
119-
'dump_params_yaml_verbose',
120-
'dump_params_md_verbose',
121-
'dump_params_yaml',
122-
'dump_params_multiple',
12387
'dump_params_error']
12488
]
12589
for process, output_file in zip(processes_to_test[:-1], output_files[:-1]):
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#! /usr/bin/env python3
2+
# Copyright (c) 2020 Sarthak Mittal
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
18+
import unittest
19+
20+
from launch import LaunchDescription
21+
from launch.actions import ExecuteProcess
22+
23+
import launch_testing
24+
import launch_testing.actions
25+
import launch_testing.asserts
26+
import launch_testing.util
27+
import launch_testing_ros
28+
29+
import pytest
30+
31+
32+
@pytest.mark.launch_test
33+
def generate_test_description():
34+
launch_description = LaunchDescription()
35+
launch_description.add_action(
36+
ExecuteProcess(
37+
cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')],
38+
name='test_dump_params')
39+
)
40+
processes_to_test = [
41+
ExecuteProcess(
42+
cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params'],
43+
name='test_dump_params_markdown',
44+
output='screen'),
45+
ExecuteProcess(
46+
cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'md', '-n', 'test_dump_params', '-v'],
47+
name='test_dump_params_markdown_verbose',
48+
output='screen')
49+
]
50+
for process in processes_to_test:
51+
launch_description.add_action(process)
52+
launch_description.add_action(
53+
launch_testing.actions.ReadyToTest()
54+
)
55+
return launch_description, {'processes_to_test': processes_to_test}
56+
57+
58+
# Tests without a unittest to run concurrently with
59+
# the processes under test throw an exception
60+
# The following is a dummy test to suppress the traceback
61+
# https://github.com/ros2/launch/issues/380
62+
63+
class TestLoggingOutputFormat(unittest.TestCase):
64+
65+
def test_logging_output(self, proc_info, processes_to_test):
66+
for process_name in processes_to_test:
67+
proc_info.assertWaitForShutdown(process=process_name, timeout=10)
68+
69+
70+
@launch_testing.post_shutdown_test()
71+
class TestDumpParams(unittest.TestCase):
72+
73+
def test_processes_output(self, proc_output, processes_to_test):
74+
"""Test all processes output against expectations."""
75+
from launch_testing.tools.output import get_default_filtered_prefixes
76+
output_filter = launch_testing_ros.tools.basic_output_filter(
77+
filtered_prefixes=get_default_filtered_prefixes()
78+
)
79+
output_files = [
80+
os.path.join(os.path.dirname(__file__), out)
81+
for out in ['dump_params_md',
82+
'dump_params_md_verbose']
83+
]
84+
for process, output_file in zip(processes_to_test, output_files):
85+
launch_testing.asserts.assertInStdout(
86+
proc_output,
87+
expected_output=launch_testing.tools.expected_output_from_file(
88+
path=output_file),
89+
process=process, output_filter=output_filter
90+
)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#! /usr/bin/env python3
2+
# Copyright (c) 2020 Sarthak Mittal
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
18+
import unittest
19+
20+
from launch import LaunchDescription
21+
from launch.actions import ExecuteProcess
22+
23+
import launch_testing
24+
import launch_testing.actions
25+
import launch_testing.asserts
26+
import launch_testing.util
27+
import launch_testing_ros
28+
29+
import pytest
30+
31+
32+
@pytest.mark.launch_test
33+
def generate_test_description():
34+
launch_description = LaunchDescription()
35+
launch_description.add_action(
36+
ExecuteProcess(
37+
cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')],
38+
name='test_dump_params')
39+
)
40+
launch_description.add_action(
41+
ExecuteProcess(
42+
cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py'),
43+
'test_dump_params_copy'],
44+
name='test_dump_params_copy')
45+
)
46+
processes_to_test = [
47+
ExecuteProcess(
48+
cmd=[os.getenv('TEST_EXECUTABLE'), '-f', 'error', '-n', 'test_dump_params'],
49+
name='test_dump_params_bad_format',
50+
output='screen'),
51+
ExecuteProcess(
52+
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params,test_dump_params_copy'],
53+
name='test_dump_params_multiple',
54+
output='screen')
55+
]
56+
for process in processes_to_test:
57+
launch_description.add_action(process)
58+
launch_description.add_action(
59+
launch_testing.actions.ReadyToTest()
60+
)
61+
return launch_description, {'processes_to_test': processes_to_test}
62+
63+
64+
# Tests without a unittest to run concurrently with
65+
# the processes under test throw an exception
66+
# The following is a dummy test to suppress the traceback
67+
# https://github.com/ros2/launch/issues/380
68+
69+
class TestLoggingOutputFormat(unittest.TestCase):
70+
71+
def test_logging_output(self, proc_info, processes_to_test):
72+
for process_name in processes_to_test:
73+
proc_info.assertWaitForShutdown(process=process_name, timeout=10)
74+
75+
76+
@launch_testing.post_shutdown_test()
77+
class TestDumpParams(unittest.TestCase):
78+
79+
def test_processes_output(self, proc_output, processes_to_test):
80+
"""Test all processes output against expectations."""
81+
from launch_testing.tools.output import get_default_filtered_prefixes
82+
output_filter = launch_testing_ros.tools.basic_output_filter(
83+
filtered_prefixes=get_default_filtered_prefixes()
84+
)
85+
output_files = [
86+
os.path.join(os.path.dirname(__file__), out)
87+
for out in ['dump_params_yaml',
88+
'dump_params_multiple']
89+
]
90+
for process, output_file in zip(processes_to_test[:-1], output_files[:-1]):
91+
launch_testing.asserts.assertInStdout(
92+
proc_output,
93+
expected_output=launch_testing.tools.expected_output_from_file(
94+
path=output_file),
95+
process=process, output_filter=output_filter
96+
)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#! /usr/bin/env python3
2+
# Copyright (c) 2020 Sarthak Mittal
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
18+
import unittest
19+
20+
from launch import LaunchDescription
21+
from launch.actions import ExecuteProcess
22+
23+
import launch_testing
24+
import launch_testing.actions
25+
import launch_testing.asserts
26+
import launch_testing.util
27+
import launch_testing_ros
28+
29+
import pytest
30+
31+
32+
@pytest.mark.launch_test
33+
def generate_test_description():
34+
launch_description = LaunchDescription()
35+
launch_description.add_action(
36+
ExecuteProcess(
37+
cmd=[os.path.join(os.path.dirname(__file__), 'test_dump_params_node.py')],
38+
name='test_dump_params')
39+
)
40+
processes_to_test = [
41+
ExecuteProcess(
42+
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params'],
43+
name='test_dump_params_yaml',
44+
output='screen'),
45+
ExecuteProcess(
46+
cmd=[os.getenv('TEST_EXECUTABLE'), '-n', 'test_dump_params', '-v'],
47+
name='test_dump_params_yaml_verbose',
48+
output='screen')
49+
]
50+
for process in processes_to_test:
51+
launch_description.add_action(process)
52+
launch_description.add_action(
53+
launch_testing.actions.ReadyToTest()
54+
)
55+
return launch_description, {'processes_to_test': processes_to_test}
56+
57+
58+
# Tests without a unittest to run concurrently with
59+
# the processes under test throw an exception
60+
# The following is a dummy test to suppress the traceback
61+
# https://github.com/ros2/launch/issues/380
62+
63+
class TestLoggingOutputFormat(unittest.TestCase):
64+
65+
def test_logging_output(self, proc_info, processes_to_test):
66+
for process_name in processes_to_test:
67+
proc_info.assertWaitForShutdown(process=process_name, timeout=10)
68+
69+
70+
@launch_testing.post_shutdown_test()
71+
class TestDumpParams(unittest.TestCase):
72+
73+
def test_processes_output(self, proc_output, processes_to_test):
74+
"""Test all processes output against expectations."""
75+
from launch_testing.tools.output import get_default_filtered_prefixes
76+
output_filter = launch_testing_ros.tools.basic_output_filter(
77+
filtered_prefixes=get_default_filtered_prefixes()
78+
)
79+
output_files = [
80+
os.path.join(os.path.dirname(__file__), out)
81+
for out in ['dump_params_yaml',
82+
'dump_params_yaml_verbose']
83+
]
84+
for process, output_file in zip(processes_to_test, output_files):
85+
launch_testing.asserts.assertInStdout(
86+
proc_output,
87+
expected_output=launch_testing.tools.expected_output_from_file(
88+
path=output_file),
89+
process=process, output_filter=output_filter
90+
)

0 commit comments

Comments
 (0)