-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add value rewrites to RewrittenYaml #5191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveMacenski
merged 5 commits into
ros-navigation:main
from
leander-dsouza:add_value_rewrites
May 27, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8090275
Added context manager for safe file closing and prevent warnings.
leander-dsouza 8b374d9
Implement value_rewrites to ReWrittenYaml.
leander-dsouza 22799b6
Use placeholders for costmap filters using the new value rewrite feat…
leander-dsouza d00291a
Enable system tests to use value rewrites.
leander-dsouza 2260870
Define remappings for costmap filters instead of inline substitution.
leander-dsouza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ install | |
| __pycache__/ | ||
| *.py[cod] | ||
| .ipynb_checkpoints | ||
| .pytest_cache/ | ||
|
|
||
| sphinx_doc/_build | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # Copyright (c) 2025 Leander Stephen Desouza | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import tempfile | ||
| from typing import Generator | ||
|
|
||
| import launch | ||
| from launch.substitutions import LaunchConfiguration | ||
| from nav2_common.launch import RewrittenYaml | ||
| import pytest | ||
| import yaml | ||
|
|
||
|
|
||
| class TestRewrittenYamlValueRewrites: | ||
| """Test that value rewrites work correctly in RewrittenYaml.""" | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup_teardown(self) -> Generator[None, None, None]: | ||
| # Create a temporary YAML file for testing | ||
| self.test_yaml = tempfile.NamedTemporaryFile(mode='w', delete=False) | ||
| self.test_yaml.write("""\ | ||
| param0: placeholder_bool | ||
| param1: placeholder_string | ||
| param2: placeholder_float | ||
| param3: placeholder_int | ||
| param4: placeholder_list | ||
| param5: placeholder_dict | ||
| nested: | ||
| param6: placeholder_bool | ||
| param7: placeholder_string | ||
| param8: placeholder_float | ||
| param9: placeholder_int | ||
| param10: placeholder_list | ||
| param11: placeholder_dict | ||
| other_value: 42 | ||
| list_values: | ||
| - placeholder_bool | ||
| - placeholder_string | ||
| - placeholder_float | ||
| - placeholder_int | ||
| - placeholder_list | ||
| - placeholder_dict | ||
| - normal_value | ||
| """) | ||
| self.test_yaml.close() | ||
| yield | ||
| os.unlink(self.test_yaml.name) | ||
|
|
||
| def test_value_rewrites(self) -> None: | ||
| """Test that value rewrites work for various types.""" | ||
| # Set up launch configurations for our test values | ||
| launch_configurations = { | ||
| 'test_bool': 'true', | ||
| 'test_string': 'replaced_string', | ||
| 'test_float': '3.14', | ||
| 'test_int': '100', | ||
| 'test_list': '["string", 42, 2.718, ["sublist_item1", "sublist_item2"]]', | ||
| 'test_dict': ('{"key1": "value1", "key2": 2, "key3": 3.14, ' | ||
| '"key4": ["list_item1", "list_item2"]}') | ||
| } | ||
| context = launch.LaunchContext() | ||
| for key, value in launch_configurations.items(): | ||
| context.launch_configurations[key] = value | ||
|
|
||
| value_rewrites = { | ||
| 'placeholder_bool': LaunchConfiguration('test_bool'), | ||
| 'placeholder_string': LaunchConfiguration('test_string'), | ||
| 'placeholder_float': LaunchConfiguration('test_float'), | ||
| 'placeholder_int': LaunchConfiguration('test_int'), | ||
| 'placeholder_list': LaunchConfiguration('test_list'), | ||
| 'placeholder_dict': LaunchConfiguration('test_dict'), | ||
| } | ||
|
|
||
| rewriter = RewrittenYaml( | ||
| source_file=self.test_yaml.name, | ||
| param_rewrites={}, | ||
| value_rewrites=value_rewrites, | ||
| convert_types=True, | ||
| ) | ||
| output_file = rewriter.perform(context) | ||
|
|
||
| try: | ||
| with open(output_file) as f: | ||
| result = yaml.safe_load(f) | ||
|
|
||
| assert result['param0'] is True | ||
| assert result['param1'] == 'replaced_string' | ||
| assert result['param2'] == 3.14 | ||
| assert result['param3'] == 100 | ||
| assert result['param4'] == \ | ||
| '["string", 42, 2.718, ["sublist_item1", "sublist_item2"]]' | ||
| assert result['param5'] == \ | ||
| '{"key1": "value1", "key2": 2, "key3": 3.14, "key4": ["list_item1", "list_item2"]}' | ||
|
|
||
| # Check nested values | ||
| assert result['nested']['param6'] is True | ||
| assert result['nested']['param7'] == 'replaced_string' | ||
| assert result['nested']['param8'] == 3.14 | ||
| assert result['nested']['param9'] == 100 | ||
| assert result['nested']['param10'] == \ | ||
| '["string", 42, 2.718, ["sublist_item1", "sublist_item2"]]' | ||
| assert result['nested']['param11'] == \ | ||
| '{"key1": "value1", "key2": 2, "key3": 3.14, "key4": ["list_item1", "list_item2"]}' | ||
|
|
||
| # Check list values | ||
| assert result['list_values'][0] is True | ||
| assert result['list_values'][1] == 'replaced_string' | ||
| assert result['list_values'][2] == 3.14 | ||
| assert result['list_values'][3] == 100 | ||
| assert result['list_values'][4] == \ | ||
| '["string", 42, 2.718, ["sublist_item1", "sublist_item2"]]' | ||
| assert result['list_values'][5] == \ | ||
| '{"key1": "value1", "key2": 2, "key3": 3.14, "key4": ["list_item1", "list_item2"]}' | ||
|
|
||
| # Check other values remain unchanged | ||
| assert result['nested']['other_value'] == 42 | ||
| assert result['list_values'][6] == 'normal_value' | ||
|
|
||
| finally: | ||
| if os.path.exists(output_file): | ||
| os.unlink(output_file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.