Skip to content

Commit 5d4279a

Browse files
committed
WIP Fixes for failing tests.
Distro A, OPSEC #4584. You may have additional rights; please see https://rosmilitary.org/faq/?category=ros-2-license Signed-off-by: matthew.lanting <[email protected]>
1 parent 8ba498f commit 5d4279a

File tree

9 files changed

+50
-25
lines changed

9 files changed

+50
-25
lines changed

launch_ros/launch_ros/actions/node.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from launch.frontend import Parser
2929
from launch.frontend.type_utils import get_data_type_from_identifier
3030

31-
from launch.launch_context import LaunchContext
3231
from launch.some_substitutions_type import SomeSubstitutionsType
3332

3433
from launch_ros.descriptions import Node as NodeDescription
@@ -130,15 +129,15 @@ def __init__(
130129
"""
131130
self.__node_desc = NodeDescription(node_name=name, node_namespace=namespace,
132131
parameters=parameters, remappings=remappings)
133-
ros_exec_kwargs = {'additional_env': additional_env, 'arguments': arguments}
132+
ros_exec_kwargs = {'additional_env': additional_env}
134133
self.__ros_exec = RosExecutable(package=package, executable=executable,
135-
nodes=[self.__node_desc])
134+
arguments=arguments, ros_arguments=ros_arguments,
135+
nodes=[self.__node_desc], **ros_exec_kwargs)
136136
super().__init__(process_description=self.__ros_exec, **kwargs)
137137

138138
def is_node_name_fully_specified(self):
139139
return self.__node_desc.is_node_name_fully_specified()
140140

141-
142141
@staticmethod
143142
def parse_nested_parameters(params, parser):
144143
"""Normalize parameters as expected by Node constructor argument."""

launch_ros/launch_ros/descriptions/node.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
from launch_ros.utilities import make_namespace_absolute
5757
from launch_ros.utilities import normalize_parameters
5858
from launch_ros.utilities import normalize_remap_rules
59-
from launch_ros.utilities import prefix_namespace
6059
from launch_ros.utilities import plugin_support
60+
from launch_ros.utilities import prefix_namespace
6161

6262
from rclpy.validate_namespace import validate_namespace
6363
from rclpy.validate_node_name import validate_node_name
@@ -89,7 +89,13 @@ def __init__(self):
8989
super(NodeActionExtension, self).__init__()
9090
plugin_support.satisfies_version(self.EXTENSION_POINT_VERSION, '^0.1')
9191

92-
def prepare_for_execute(self, context, ros_specific_arguments, ros_executable, node_description):
92+
def prepare_for_execute(
93+
self,
94+
context,
95+
ros_specific_arguments,
96+
ros_executable,
97+
node_description
98+
):
9399
"""
94100
Perform any actions prior to the node's process being launched.
95101
@@ -271,7 +277,7 @@ def _get_parameter_rule(self, param: 'Parameter', context: LaunchContext):
271277

272278
def prepare(self, context: LaunchContext, executable: Executable, action: Action) -> None:
273279
self._perform_substitutions(context, executable)
274-
280+
275281
# Prepare any traits which may be defined for this node
276282
if self.__traits is not None:
277283
for trait in self.__traits:
@@ -374,7 +380,7 @@ def _perform_substitutions(self, context: LaunchContext, executable: Executable)
374380
# Prepare the ros_specific_arguments list and add it to the context so that the
375381
# LocalSubstitution placeholders added to the the cmd can be expanded using the contents.
376382
ros_specific_arguments: Dict[str, Union[str, List[str]]] = {}
377-
original_name_prefix = ""
383+
original_name_prefix = ''
378384
if self.__expanded_original_node_name is not self.UNSPECIFIED_NODE_NAME:
379385
original_name_prefix = '{}:'.format(self.__expanded_original_node_name)
380386
if self.__node_name is not None:
@@ -386,6 +392,7 @@ def _perform_substitutions(self, context: LaunchContext, executable: Executable)
386392
original_name_prefix, self.__expanded_node_namespace
387393
)
388394
# Give extensions a chance to prepare for execution
395+
cmd_extension = []
389396
for extension in self.__extensions.values():
390397
cmd_extension, ros_specific_arguments = extension.prepare_for_execute(
391398
context,

launch_ros/launch_ros/descriptions/ros_executable.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(
4343
executable: Optional[SomeSubstitutionsType] = None,
4444
package: Optional[SomeSubstitutionsType] = None,
4545
nodes: Iterable[Node] = None,
46+
ros_arguments: Optional[Iterable[SomeSubstitutionsType]] = None,
47+
arguments: Optional[Iterable[SomeSubstitutionsType]] = None,
4648
**kwargs
4749
) -> None:
4850
"""
@@ -58,10 +60,13 @@ def __init__(
5860
else:
5961
cmd = [executable]
6062

63+
if ros_arguments is not None:
64+
arguments += ['--ros-args'] + ros_arguments
65+
6166
self.__package = package
6267
self.__executable = executable
6368
self.__nodes = nodes
64-
super().__init__(cmd=cmd, **kwargs)
69+
super().__init__(cmd=cmd, arguments=arguments, **kwargs)
6570

6671
@property
6772
def package(self):

test_launch_ros/test/test_launch_ros/actions/test_lifecycle_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ def test_node_name():
5252
)
5353
lc = LaunchContext()
5454
for node in node_object.ros_exec.nodes:
55-
node._perform_substitutions(lc, [])
55+
node._perform_substitutions(lc, node_object.ros_exec)
5656
assert node_object.is_node_name_fully_specified() is True

test_launch_ros/test/test_launch_ros/actions/test_node.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ def test_launch_node_with_parameter_descriptions(self):
195195
name, value = item.split(':=')
196196
parameters.append((name, yaml.safe_load(value)))
197197
assert parameters == [
198-
('param1', 'param1_value'),
199-
('param2', ['param2', '_value']),
200-
('param_group1.list_params', [1.2, 3.4]),
201-
('param_group1.param_group2.param2_values', ['param2_value']),
202-
('param3', ''),
198+
('my_node:param1', 'param1_value'),
199+
('my_node:param2', ['param2', '_value']),
200+
('my_node:param_group1.list_params', [1.2, 3.4]),
201+
('my_node:param_group1.param_group2.param2_values', ['param2_value']),
202+
('my_node:param3', ''),
203203
]
204204

205205
def test_launch_node_with_parameter_dict(self):
@@ -361,5 +361,5 @@ def get_test_node_name_parameters():
361361
def test_node_name(node_object, expected_result):
362362
lc = LaunchContext()
363363
for node in node_object.ros_exec.nodes:
364-
node._perform_substitutions(lc, [])
364+
node._perform_substitutions(lc, node_object.ros_exec)
365365
assert node_object.is_node_name_fully_specified() is expected_result

test_launch_ros/test/test_launch_ros/actions/test_push_ros_namespace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ def test_push_ros_namespace(config):
121121
if config.second_push_ns is not None:
122122
pns2 = PushRosNamespace(config.second_push_ns)
123123
pns2.execute(lc)
124-
node = Node(
124+
node_object = Node(
125125
package='dont_care',
126126
executable='whatever',
127127
namespace=config.node_ns,
128128
name=config.node_name
129129
)
130130
for node in node_object.ros_exec.nodes:
131-
node._perform_substitutions(lc, [])
131+
node._perform_substitutions(lc, node_object.ros_exec)
132132
expected_ns = (
133133
config.expected_ns if config.expected_ns is not None else
134134
NodeDescription.UNSPECIFIED_NODE_NAMESPACE

test_launch_ros/test/test_launch_ros/actions/test_set_parameter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def test_set_param_with_node():
120120
set_param = SetParameter(name='my_param', value='my_value')
121121
set_param.execute(lc)
122122
for node_instance in node.ros_exec.nodes:
123-
node_instance._perform_substitutions(lc, [])
123+
node_instance._perform_substitutions(lc, node.ros_exec)
124124
actual_command = [perform_substitutions(lc, item) for item in
125-
node.cmd if type(item[0]) == TextSubstitution]
125+
node.ros_exec.cmd if type(item[0]) == TextSubstitution]
126126
assert actual_command.count('--params-file') == 1
127127
assert actual_command.count('-p') == 1
128128

test_launch_ros/test/test_launch_ros/actions/test_set_parameters_from_file.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import os
1818

19+
from _collections import defaultdict
20+
1921
from launch import LaunchContext
2022
from launch.actions import PopLaunchConfigurations
2123
from launch.actions import PushLaunchConfigurations
@@ -34,6 +36,14 @@ class MockContext:
3436

3537
def __init__(self):
3638
self.launch_configurations = {}
39+
self.locals = lambda: None
40+
self.locals.unique_ros_node_names = defaultdict(int)
41+
42+
def extend_globals(self, val):
43+
pass
44+
45+
def extend_locals(self, val):
46+
pass
3747

3848
def perform_substitution(self, sub):
3949
return sub.perform(None)
@@ -74,14 +84,18 @@ def test_set_param_with_node():
7484
set_param_single = SetParameter(name='my_param', value='my_value')
7585
set_param_file.execute(lc)
7686
set_param_single.execute(lc)
77-
node_1._perform_substitutions(lc)
78-
node_2._perform_substitutions(lc)
87+
# node_1._perform_substitutions(lc)
88+
for node_description in node_1.ros_exec.nodes:
89+
node_description._perform_substitutions(lc, node_1.ros_exec)
90+
# node_2._perform_substitutions(lc)
91+
for node_description in node_2.ros_exec.nodes:
92+
node_description._perform_substitutions(lc, node_2.ros_exec)
7993

8094
actual_command_1 = [perform_substitutions(lc, item) for item in
81-
node_1.cmd if type(item[0]) == TextSubstitution]
95+
node_1.ros_exec.cmd if type(item[0]) == TextSubstitution]
8296

8397
actual_command_2 = [perform_substitutions(lc, item) for item in
84-
node_2.cmd if type(item[0]) == TextSubstitution]
98+
node_2.ros_exec.cmd if type(item[0]) == TextSubstitution]
8599

86100
assert actual_command_1[3] == '--params-file'
87101
assert os.path.isfile(actual_command_1[4])

test_launch_ros/test/test_launch_ros/actions/test_set_remap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_set_remap_with_node():
9494
set_remap = SetRemap('from1', 'to1')
9595
set_remap.execute(lc)
9696
for node_instance in node.ros_exec.nodes:
97-
node_instance._perform_substitutions(lc, [])
97+
node_instance._perform_substitutions(lc, node.ros_exec)
9898
assert len(node.expanded_remapping_rules) == 2
9999
assert node.expanded_remapping_rules == [('from1', 'to1'), ('from2', 'to2')]
100100

0 commit comments

Comments
 (0)