File tree Expand file tree Collapse file tree 4 files changed +97
-12
lines changed
launch_xml/test/launch_xml
launch_yaml/test/launch_yaml Expand file tree Collapse file tree 4 files changed +97
-12
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 1515"""Test parsing an executable action."""
1616
1717import io
18+ import os
1819from pathlib import Path
1920import sys
2021import 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
7885def 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
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 1515"""Test parsing an executable action."""
1616
1717import io
18+ import os
19+ import sys
1820import textwrap
1921
2022from 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
You can’t perform that action at this time.
0 commit comments