Skip to content

Commit 5b90cb8

Browse files
committed
added test case
Signed-off-by: Markus Kramer <[email protected]>
1 parent 55e6e9f commit 5b90cb8

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

launch_ros/test/test_cli_remap.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2025 Open Source Robotics Foundation, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import unittest
18+
import subprocess
19+
20+
class TestRemapArgument(unittest.TestCase):
21+
"""Test the --remap command line argument for ros2 launch."""
22+
23+
def test_remap_argument(self):
24+
"""Test that the --remap argument correctly remaps topics."""
25+
try:
26+
# Start the talker_listener launch file with remapping
27+
launch_proc_remapped = subprocess.Popen(
28+
['ros2', 'launch', 'demo_nodes_cpp', 'talker_listener_launch.py',
29+
'--remap', '/chatter:=/chatter_remapped'],
30+
stdout=subprocess.PIPE,
31+
stderr=subprocess.PIPE
32+
)
33+
34+
# Run ros2 topic list to get the remapped topics
35+
result = subprocess.run(['ros2', 'topic', 'list'],
36+
stdout=subprocess.PIPE,
37+
stderr=subprocess.PIPE,
38+
text=True,
39+
check=True)
40+
remapped_topics = result.stdout.strip().split('\n')
41+
42+
# Verify /chatter is NOT in the list
43+
self.assertNotIn('/chatter', remapped_topics,
44+
f"Did not expect to find /chatter after remapping. Topics: {remapped_topics}")
45+
46+
# Verify /chatter_remapped IS in the list
47+
self.assertIn('/chatter_remapped', remapped_topics,
48+
f"Expected to find /chatter_remapped after remapping. Topics: {remapped_topics}")
49+
50+
finally:
51+
# Clean up
52+
if 'launch_proc_remapped' in locals():
53+
launch_proc_remapped.terminate()
54+
try:
55+
launch_proc_remapped.wait(timeout=5)
56+
except subprocess.TimeoutExpired:
57+
launch_proc_remapped.kill()
58+
launch_proc_remapped.wait()
59+
60+
61+
if __name__ == '__main__':
62+
unittest.main()

0 commit comments

Comments
 (0)