|
| 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