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
Add frontend parsing methods for Node, ExecutableInPackage and FindPackage substitution #23
Merged
Merged
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8198671
Add node parsing method and test
ivanpauno 3fbd877
Used parse_substitution in parse Node method
ivanpauno b93e86d
Corrected node parsing method and test with lastest changes
ivanpauno a0de256
Expose ExecutableInPackage substitution
ivanpauno 9869bbd
Updated node parsing method with typed get_attr change.
ivanpauno 011f188
Correct param and env parsing in node parsing method
ivanpauno 1d1559b
Add yaml node example. Reoredered test folders
ivanpauno 7ff4c2f
Address review comments
ivanpauno 6c986fa
Allow code reusage with base class parsing method
ivanpauno f5f88c5
Parameterize node frontend tests. Add missing test dependencies in pa…
ivanpauno 55df869
Handle parameters correctly after bb82f311255b02ee9306fc5fd9ccaa0f63f…
ivanpauno 02184a3
Revert "Handle parameters correctly after bb82f311255b02ee9306fc5fd9c…
ivanpauno 6799cdd
Deleted unused node.xml file
ivanpauno f884836
Parse parameter values as substitutions
ivanpauno e2e8f7a
Better testing for node parsing
ivanpauno cd8a01f
Updated after addressing comments in launch PR
ivanpauno df0b0dd
Address PR comments
ivanpauno 3f67583
Updated after merging launch_frontend into launch
ivanpauno f58b863
Update after change of get_attr types argument in launch_frontend
ivanpauno 0608922
Updated old import in test
ivanpauno 0a16d4e
Correct param from option parsing. Add find-package substitution. Upd…
ivanpauno 110fb1a
Avoid unnecessary installation of testing file
ivanpauno b8b6b14
Address PR comments
ivanpauno 009041a
Renamed launch_frontend to launch
ivanpauno dfc2292
Correct Node parsing method after change in ExecuteProcess
ivanpauno 7dede1f
Add more test cases for loading params
ivanpauno f202a63
Allow parameter name to be a substitution
ivanpauno a3ca07f
Rename launch_frontend test folder to frontend
ivanpauno 07f162d
Add new tests for node parameters
ivanpauno c1c1d6a
Update get_attr argument from types to data_type
ivanpauno 3a95e38
Correct parameters parsing and test
ivanpauno 840b279
Change code style. Delete old comment
ivanpauno File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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,5 @@ | ||
my_ns: | ||
my_node: | ||
ros__parameters: | ||
param_from_file_1: 1 | ||
param_from_file_2: 'asd' |
143 changes: 143 additions & 0 deletions
143
test_launch_ros/test/test_launch_ros/frontend/test_node_frontend.py
This file contains 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,143 @@ | ||
# Copyright 2019 Open Source Robotics Foundation, Inc. | ||
# | ||
# 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. | ||
|
||
"""Example of how to parse an xml.""" | ||
|
||
import io | ||
import pathlib | ||
import textwrap | ||
|
||
from launch import LaunchService | ||
from launch.frontend import Parser | ||
|
||
from launch_ros.utilities import evaluate_parameters | ||
|
||
import pytest | ||
|
||
yaml_params = str(pathlib.Path(__file__).parent / 'params.yaml') | ||
xml_file = \ | ||
r""" | ||
<launch> | ||
<let name="a_string" value="\'[2, 5, 8]\'"/> | ||
<let name="a_list" value="[2, 5, 8]"/> | ||
<node package="demo_nodes_py" executable="talker_qos" output="screen" name="my_node" namespace="my_ns" args="--number_of_cycles 1"> | ||
<param name="param1" value="ads"/> | ||
<param name="param_group1"> | ||
<param name="param_group2"> | ||
<param name="param2" value="2"/> | ||
</param> | ||
<param name="param3" value="2, 5, 8" value-sep=", "/> | ||
<param name="param4" value="$(var a_list)"/> | ||
<param name="param5" value="$(var a_string)"/> | ||
<param name="param6" value="2., 5., 8." value-sep=", "/> | ||
<param name="param7" value="'2', '5', '8'" value-sep=", "/> | ||
<param name="param8" value="''2'', ''5'', ''8''" value-sep=", "/> | ||
<param name="param9" value="\'2\', \'5\', \'8\'" value-sep=", "/> | ||
<param name="param10" value="''asd'', ''bsd'', ''csd''" value-sep=", "/> | ||
<param name="param11" value="'\asd', '\bsd', '\csd'" value-sep=", "/> | ||
</param> | ||
<param from="{}"/> | ||
<env name="var" value="1"/> | ||
</node> | ||
</launch> | ||
""".format(yaml_params) # noqa: E501 | ||
xml_file = textwrap.dedent(xml_file) | ||
yaml_file = \ | ||
r""" | ||
launch: | ||
- let: | ||
name: 'a_string' | ||
value: "'[2, 5, 8]'" | ||
- let: | ||
name: 'a_list' | ||
value: '[2, 5, 8]' | ||
- node: | ||
package: demo_nodes_py | ||
executable: talker_qos | ||
output: screen | ||
name: my_node | ||
namespace: my_ns | ||
args: '--number_of_cycles 1' | ||
param: | ||
- name: param1 | ||
value: ads | ||
- name: param_group1 | ||
param: | ||
- name: param_group2 | ||
param: | ||
- name: param2 | ||
value: 2 | ||
- name: param3 | ||
value: [2, 5, 8] | ||
- name: param4 | ||
value: $(var a_list) | ||
- name: param5 | ||
value: $(var a_string) | ||
- name: param6 | ||
value: [2., 5., 8.] | ||
- name: param7 | ||
value: ['2', '5', '8'] | ||
- name: param8 | ||
value: ["'2'", "'5'", "'8'"] | ||
- name: param9 | ||
value: ["\\'2\\'", "\\'5\\'", "\\'8\\'"] | ||
- name: param10 | ||
value: ["'asd'", "'bsd'", "'csd'"] | ||
- name: param11 | ||
value: ['\asd', '\bsd', '\csd'] | ||
- from: {} | ||
env: | ||
- name: var | ||
value: '1' | ||
""".format(yaml_params) # noqa: E501 | ||
yaml_file = textwrap.dedent(yaml_file) | ||
|
||
|
||
@pytest.mark.parametrize('file', (xml_file, yaml_file)) | ||
def test_node_frontend(file): | ||
"""Parse node xml example.""" | ||
root_entity, parser = Parser.load(io.StringIO(file)) | ||
ld = parser.parse_description(root_entity) | ||
ls = LaunchService() | ||
ls.include_launch_description(ld) | ||
assert(0 == ls.run()) | ||
evaluated_parameters = evaluate_parameters( | ||
ls.context, | ||
ld.describe_sub_entities()[2]._Node__parameters | ||
) | ||
assert isinstance(evaluated_parameters[0], pathlib.Path) | ||
assert isinstance(evaluated_parameters[1], dict) | ||
param_dict = evaluated_parameters[1] | ||
assert 'param1' in param_dict | ||
assert param_dict['param1'] == 'ads' | ||
assert 'param_group1.param_group2.param2' in param_dict | ||
assert 'param_group1.param3' in param_dict | ||
assert 'param_group1.param4' in param_dict | ||
assert 'param_group1.param5' in param_dict | ||
assert 'param_group1.param6' in param_dict | ||
assert 'param_group1.param7' in param_dict | ||
assert 'param_group1.param8' in param_dict | ||
assert 'param_group1.param9' in param_dict | ||
assert 'param_group1.param10' in param_dict | ||
assert 'param_group1.param11' in param_dict | ||
assert param_dict['param_group1.param_group2.param2'] == 2 | ||
assert param_dict['param_group1.param3'] == (2, 5, 8) | ||
assert param_dict['param_group1.param4'] == (2, 5, 8) | ||
assert param_dict['param_group1.param5'] == '[2, 5, 8]' | ||
assert param_dict['param_group1.param6'] == (2., 5., 8.) | ||
assert param_dict['param_group1.param7'] == ('2', '5', '8') | ||
assert param_dict['param_group1.param8'] == ("'2'", "'5'", "'8'") | ||
assert param_dict['param_group1.param9'] == ("'2'", "'5'", "'8'") | ||
assert param_dict['param_group1.param10'] == ("'asd'", "'bsd'", "'csd'") | ||
assert param_dict['param_group1.param11'] == ('asd', 'bsd', 'csd') |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanpauno just curious, why the two step assignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bad habit.