Skip to content

Commit c6f9184

Browse files
authored
fix loading parameter behavior from yaml file. (#864)
Ref: #863 Signed-off-by: Tomoya Fujita <[email protected]>
1 parent c8ed0ae commit c6f9184

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

ros2param/ros2param/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def load_parameter_file(*, node, node_name, parameter_file, use_wildcard):
3939
raise RuntimeError('Wait for service timed out waiting for '
4040
f'parameter services for node {node_name}')
4141
future = client.load_parameter_file(parameter_file, use_wildcard)
42-
parameters = list(parameter_dict_from_yaml_file(parameter_file, use_wildcard).values())
42+
parameters = list(parameter_dict_from_yaml_file(
43+
parameter_file, use_wildcard, target_nodes=[node_name]).values())
4344
rclpy.spin_until_future_complete(node, future)
4445
response = future.result()
4546
assert len(response.results) == len(parameters), 'Not all parameters set'

ros2param/test/test_verb_load.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
' ros__parameters:\n'
8787
' str_param: Override\n'
8888
)
89+
INPUT_NS_NODE_OVERLAY_PARAMETER_FILE = (
90+
f'{TEST_NAMESPACE}:\n'
91+
f' {TEST_NODE}:\n'
92+
' ros__parameters:\n'
93+
' str_param: Override\n'
94+
)
8995

9096
# Skip cli tests on Windows while they exhibit pathological behavior
9197
# https://github.com/ros2/build_farmer/issues/248
@@ -317,7 +323,7 @@ def test_verb_load_wildcard(self):
317323
assert param_load_command.wait_for_shutdown(timeout=TEST_TIMEOUT)
318324
assert param_load_command.exit_code != launch_testing.asserts.EXIT_OK
319325
assert launch_testing.tools.expect_output(
320-
expected_lines=['Param file does not contain selected parameters'],
326+
expected_lines=['Param file does not contain any valid parameters'],
321327
text=param_load_command.output,
322328
strict=False
323329
)
@@ -343,7 +349,7 @@ def test_verb_load_wildcard(self):
343349
assert params['str_param'] == 'Wildcard'
344350
assert params['int_param'] == 12345
345351

346-
# Concatenate wildcard + some overlays
352+
# Concatenate wildcard + some overlays with absolute node name
347353
filepath = self._write_param_file(tmpdir, 'params.yaml',
348354
INPUT_WILDCARD_PARAMETER_FILE + '\n' +
349355
INPUT_NODE_OVERLAY_PARAMETER_FILE)
@@ -363,3 +369,24 @@ def test_verb_load_wildcard(self):
363369
params = loaded_params[f'{TEST_NAMESPACE}/{TEST_NODE}']['ros__parameters']
364370
assert params['str_param'] == 'Override' # Overriden
365371
assert params['int_param'] == 12345 # Wildcard namespace
372+
373+
# Concatenate wildcard + some overlays with namespace and base node name
374+
filepath = self._write_param_file(tmpdir, 'params.yaml',
375+
INPUT_WILDCARD_PARAMETER_FILE + '\n' +
376+
INPUT_NS_NODE_OVERLAY_PARAMETER_FILE)
377+
with self.launch_param_load_command(
378+
arguments=[f'{TEST_NAMESPACE}/{TEST_NODE}', filepath]
379+
) as param_load_command:
380+
assert param_load_command.wait_for_shutdown(timeout=TEST_TIMEOUT)
381+
assert param_load_command.exit_code == launch_testing.asserts.EXIT_OK
382+
383+
# Dump and check that wildcard parameters were overriden if in node namespace
384+
with self.launch_param_dump_command(
385+
arguments=[f'{TEST_NAMESPACE}/{TEST_NODE}']
386+
) as param_dump_command:
387+
assert param_dump_command.wait_for_shutdown(timeout=TEST_TIMEOUT)
388+
assert param_dump_command.exit_code == launch_testing.asserts.EXIT_OK
389+
loaded_params = yaml.safe_load(param_dump_command.output)
390+
params = loaded_params[f'{TEST_NAMESPACE}/{TEST_NODE}']['ros__parameters']
391+
assert params['str_param'] == 'Override' # Overriden
392+
assert params['int_param'] == 12345 # Wildcard namespace

0 commit comments

Comments
 (0)