Skip to content

Commit 7da7c99

Browse files
authored
Add a unit test for an actual loaded launchfile (#11)
1 parent 6d473f1 commit 7da7c99

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>launch_frontend_py</name>
5-
<version>0.1.0</version>
5+
<version>0.0.0</version>
66
<description>Python frontend for writing ROS 2 launch files</description>
77
<maintainer email="[email protected]">Emerson Knapp</maintainer>
88
<license>Apache License 2.0</license>
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@
1313
# limitations under the License.
1414

1515
from launch_frontend_py import launch
16-
from launch_frontend_py.actions import arg, log
16+
from launch_frontend_py.actions import arg, executable
1717

1818

1919
def generate_launch_description():
2020
return launch([
21-
arg(name='foo'),
22-
log(
23-
level='INFO',
24-
message='I am an included launch file: foo=$(var foo)',
25-
),
26-
# TODO(emerson) make if_ work
27-
# log(
28-
# if_='$(var foo)',
29-
# level='INFO',
30-
# message='This conditional log only happened because foo is true',
31-
# ),
32-
# log(
33-
# if_='$(not $(var foo))',
34-
# level='INFO',
35-
# message='This conditional log only happened because foo is false',
36-
# ),
21+
arg(name='message', default='hello world'),
22+
executable(cmd='echo $(var message)', output='both'),
3723
])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
1415
from pathlib import Path
1516

1617
from launch_frontend_py import launch

test/test_frontend.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2025 Polymath Robotics, 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+
from pathlib import Path
16+
17+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
18+
from launch.launch_context import LaunchContext
19+
from launch.launch_description import LaunchDescription
20+
21+
THIS_DIR = Path(__file__).parent
22+
23+
24+
def test_load_basic():
25+
context = LaunchContext()
26+
27+
include = IncludeLaunchDescription(str(THIS_DIR / 'launch' / 'basic_launch.py'))
28+
print(include)
29+
included_entities = include.get_sub_entities()
30+
print(included_entities)
31+
assert len(included_entities) == 1
32+
33+
launch_desc = included_entities[0]
34+
assert isinstance(launch_desc, LaunchDescription)
35+
36+
launchfile_entities = launch_desc.describe_sub_entities()
37+
assert len(launchfile_entities) == 2
38+
39+
# The first entity is a declare()
40+
should_be_declare = launchfile_entities[0]
41+
assert isinstance(should_be_declare, DeclareLaunchArgument)
42+
should_be_declare.visit(context)
43+
44+
# Second is executable()
45+
should_be_exec = launchfile_entities[1]
46+
assert isinstance(should_be_exec, ExecuteProcess)
47+
48+
should_be_exec.prepare(context)
49+
assert should_be_exec.process_description.final_cmd == ['echo', 'hello world']

0 commit comments

Comments
 (0)