Skip to content

Commit 1d88418

Browse files
authored
Fix push-ros-namespace in xml/yaml launch files (#100)
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent 7469154 commit 1d88418

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

launch_ros/launch_ros/actions/push_ros_namespace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from launch import Action
2020
from launch import Substitution
2121
from launch.frontend import Entity
22+
from launch.frontend import expose_action
2223
from launch.frontend import Parser
2324
from launch.launch_context import LaunchContext
2425
from launch.some_substitutions_type import SomeSubstitutionsType
@@ -29,6 +30,7 @@
2930
from rclpy.validate_namespace import validate_namespace
3031

3132

33+
@expose_action('push-ros-namespace')
3234
class PushRosNamespace(Action):
3335
"""
3436
Action that pushes the ros namespace.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2019 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Example of how to parse an xml."""
16+
17+
import io
18+
import textwrap
19+
20+
from launch import LaunchService
21+
from launch.frontend import Parser
22+
23+
import pytest
24+
25+
xml_file = \
26+
r"""
27+
<launch>
28+
<push-ros-namespace namespace="asd"/>
29+
</launch>
30+
"""
31+
xml_file = textwrap.dedent(xml_file)
32+
yaml_file = \
33+
r"""
34+
launch:
35+
- push-ros-namespace:
36+
namespace: 'asd'
37+
"""
38+
yaml_file = textwrap.dedent(yaml_file)
39+
40+
41+
@pytest.mark.parametrize('file', (xml_file, yaml_file))
42+
def test_node_frontend(file):
43+
"""Parse node xml example."""
44+
root_entity, parser = Parser.load(io.StringIO(file))
45+
ld = parser.parse_description(root_entity)
46+
ls = LaunchService()
47+
ls.include_launch_description(ld)
48+
assert 0 == ls.run()
49+
assert 'ros_namespace' in ls.context.launch_configurations
50+
assert '/asd' == ls.context.launch_configurations['ros_namespace']

0 commit comments

Comments
 (0)