Skip to content

Commit 8eb7c7e

Browse files
committed
add yaml and xml tests for split_arguments
Signed-off-by: William Woodall <[email protected]>
1 parent 964250e commit 8eb7c7e

File tree

4 files changed

+97
-12
lines changed

4 files changed

+97
-12
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 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+
"""Used from test_executable.py and others."""
16+
17+
18+
import sys
19+
20+
21+
def print_argv(argv):
22+
joined_args = "', '".join(argv)
23+
print(f"['{joined_args}']")
24+
sys.exit(len(argv))
25+
26+
27+
if __name__ == '__main__':
28+
print_argv(sys.argv)

launch_xml/test/launch_xml/test_executable.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Test parsing an executable action."""
1616

1717
import io
18+
import os
1819
from pathlib import Path
1920
import sys
2021
import textwrap
@@ -67,25 +68,28 @@ def test_executable_wrong_subtag():
6768
assert '`executable`' in str(excinfo.value)
6869
assert 'whats_this' in str(excinfo.value)
6970

70-
# <let name="script" value="print('hello world')" />
71-
split_arguments_example = f"""
71+
72+
split_arguments_example1 = f"""
7273
<launch>
73-
<executable cmd="{sys.executable} -c 'print(0)'" log_cmd="True" split_arguments="True" />
74+
<let name="args" value="--some-arg 'some string'" />
75+
<executable
76+
cmd="{sys.executable} {os.path.join(os.path.dirname(__file__), 'arg_echo.py')} $(var args)"
77+
log_cmd="True"
78+
split_arguments="True"
79+
output="screen"
80+
/>
7481
</launch>
7582
"""
7683

7784

7885
def test_executable_with_split_arguments():
7986
"""Parse node xml example."""
80-
root_entity, parser = Parser.load(io.StringIO(split_arguments_example))
87+
root_entity, parser = Parser.load(io.StringIO(split_arguments_example1))
8188
ld = parser.parse_description(root_entity)
8289
ls = LaunchService()
8390
ls.include_launch_description(ld)
8491
assert 0 == ls.run()
8592

86-
executable = ld.entities[0]
87-
assert False, executable.get_stdout()
88-
89-
90-
if __name__ == '__main__':
91-
test_executable()
93+
executable = ld.entities[-1]
94+
# expect a return code that matches the number of arguments after the executable
95+
assert executable.return_code == 3
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 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+
"""Used from test_executable.py and others."""
16+
17+
18+
import sys
19+
20+
21+
def print_argv(argv):
22+
joined_args = "', '".join(argv)
23+
print(f"['{joined_args}']")
24+
sys.exit(len(argv))
25+
26+
27+
if __name__ == '__main__':
28+
print_argv(sys.argv)

launch_yaml/test/launch_yaml/test_executable.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"""Test parsing an executable action."""
1616

1717
import io
18+
import os
19+
import sys
1820
import textwrap
1921

2022
from launch import LaunchService
@@ -64,5 +66,28 @@ def test_executable():
6466
assert(0 == ls.run())
6567

6668

67-
if __name__ == '__main__':
68-
test_executable()
69+
split_arguments_example1 = f"""
70+
launch:
71+
- let:
72+
name: args
73+
value: '--some-arg "some string"'
74+
- executable:
75+
cmd: {sys.executable} {os.path.join(os.path.dirname(__file__), 'arg_echo.py')} $(var args)
76+
log_cmd: True
77+
shell: False
78+
split_arguments: True
79+
output: screen
80+
"""
81+
82+
83+
def test_executable_with_split_arguments():
84+
"""Parse node xml example."""
85+
root_entity, parser = Parser.load(io.StringIO(split_arguments_example1))
86+
ld = parser.parse_description(root_entity)
87+
ls = LaunchService()
88+
ls.include_launch_description(ld)
89+
assert 0 == ls.run()
90+
91+
executable = ld.entities[-1]
92+
# expect a return code that matches the number of arguments after the executable
93+
assert executable.return_code == 3

0 commit comments

Comments
 (0)