Skip to content

Commit 0c88971

Browse files
committed
Add xml and yaml test
Signed-off-by: Christian Ruf <[email protected]>
1 parent a280fc3 commit 0c88971

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2025 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+
"""Test parsing a StringJoinSubstitution in XML launch file."""
16+
17+
import io
18+
import textwrap
19+
20+
from launch.actions import DeclareLaunchArgument, SetLaunchConfiguration
21+
from launch.frontend import Parser
22+
from launch.launch_context import LaunchContext
23+
from launch.substitutions import StringJoinSubstitution
24+
25+
26+
def test_nested():
27+
xml_file = textwrap.dedent(
28+
"""
29+
<launch>
30+
<arg name="subdomain" default="wiki"/>
31+
<let name="url" value="$(string-join . https://$(var subdomain) ros org)"/>
32+
</launch>
33+
"""
34+
)
35+
root_entity, parser = Parser.load(io.StringIO(xml_file))
36+
ld = parser.parse_description(root_entity)
37+
38+
assert len(ld.entities) == 2
39+
assert isinstance(ld.describe_sub_entities()[0], DeclareLaunchArgument)
40+
assert isinstance(ld.describe_sub_entities()[1], SetLaunchConfiguration)
41+
42+
lc = LaunchContext()
43+
ld.entities[0].visit(lc)
44+
45+
let = ld.describe_sub_entities()[1]
46+
assert isinstance(let.value[0], StringJoinSubstitution)
47+
assert let.value[0].perform(lc) == 'https://wiki.ros.org'
48+
49+
50+
def test_delimiter():
51+
yaml_file = textwrap.dedent(
52+
"""
53+
<launch>
54+
<arg name="delimiter" default="^_^"/>
55+
<let name="text" value="$(string-join '($(var delimiter))' a b c)"/>
56+
</launch>
57+
"""
58+
)
59+
root_entity, parser = Parser.load(io.StringIO(yaml_file))
60+
ld = parser.parse_description(root_entity)
61+
62+
assert len(ld.entities) == 2
63+
assert isinstance(ld.entities[0], DeclareLaunchArgument)
64+
assert isinstance(ld.entities[1], SetLaunchConfiguration)
65+
66+
lc = LaunchContext()
67+
ld.entities[0].visit(lc)
68+
69+
let = ld.describe_sub_entities()[1]
70+
assert isinstance(let.value[0], StringJoinSubstitution)
71+
assert let.value[0].perform(lc) == 'a(^_^)b(^_^)c'
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2025 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+
"""Test parsing a StringJoinSubstitution in yaml launch file."""
16+
17+
import io
18+
import textwrap
19+
20+
from launch.actions import DeclareLaunchArgument, SetLaunchConfiguration
21+
from launch.frontend import Parser
22+
from launch.launch_context import LaunchContext
23+
from launch.substitutions import StringJoinSubstitution
24+
25+
26+
def test_nested():
27+
yaml_file = textwrap.dedent(
28+
"""
29+
launch:
30+
- arg:
31+
name: subdomain
32+
default: "wiki"
33+
- let:
34+
name: url
35+
value: "$(string-join . https://$(var subdomain) ros org)"
36+
"""
37+
)
38+
root_entity, parser = Parser.load(io.StringIO(yaml_file))
39+
ld = parser.parse_description(root_entity)
40+
41+
assert len(ld.entities) == 2
42+
assert isinstance(ld.describe_sub_entities()[0], DeclareLaunchArgument)
43+
assert isinstance(ld.describe_sub_entities()[1], SetLaunchConfiguration)
44+
45+
lc = LaunchContext()
46+
ld.entities[0].visit(lc)
47+
48+
let = ld.describe_sub_entities()[1]
49+
assert isinstance(let.value[0], StringJoinSubstitution)
50+
assert let.value[0].perform(lc) == 'https://wiki.ros.org'
51+
52+
53+
def test_delimiter():
54+
yaml_file = textwrap.dedent(
55+
"""
56+
launch:
57+
- arg:
58+
name: delimiter
59+
default: "^_^"
60+
- let:
61+
name: text
62+
value: "$(string-join '($(var delimiter))' a b c)"
63+
"""
64+
)
65+
root_entity, parser = Parser.load(io.StringIO(yaml_file))
66+
ld = parser.parse_description(root_entity)
67+
68+
assert len(ld.entities) == 2
69+
assert isinstance(ld.entities[0], DeclareLaunchArgument)
70+
assert isinstance(ld.entities[1], SetLaunchConfiguration)
71+
72+
lc = LaunchContext()
73+
ld.entities[0].visit(lc)
74+
75+
let = ld.describe_sub_entities()[1]
76+
assert isinstance(let.value[0], StringJoinSubstitution)
77+
assert let.value[0].perform(lc) == 'a(^_^)b(^_^)c'

0 commit comments

Comments
 (0)