-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add IncludeLaunchDescription action (#120)
fixes #115 Signed-off-by: William Woodall <[email protected]>
- Loading branch information
Showing
6 changed files
with
148 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2018 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. | ||
|
||
"""Module for the IncludeLaunchDescription action.""" | ||
|
||
from typing import List | ||
|
||
from ..action import Action | ||
from ..launch_context import LaunchContext | ||
from ..launch_description_entity import LaunchDescriptionEntity | ||
from ..launch_description_source import LaunchDescriptionSource | ||
|
||
|
||
class IncludeLaunchDescription(Action): | ||
"""Action that includes a launch description source and yields its entities when visited.""" | ||
|
||
def __init__(self, launch_description_source: LaunchDescriptionSource) -> None: | ||
"""Constructor.""" | ||
super().__init__() | ||
self.__launch_description_source = launch_description_source | ||
|
||
@property | ||
def launch_description_source(self) -> LaunchDescriptionSource: | ||
"""Getter for self.__launch_description_source.""" | ||
return self.__launch_description_source | ||
|
||
def visit(self, context: LaunchContext) -> List[LaunchDescriptionEntity]: | ||
"""Override visit to return an Entity rather than an action.""" | ||
return [self.__launch_description_source.launch_description] |
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,57 @@ | ||
# Copyright 2018 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. | ||
|
||
"""Module for the LaunchDescriptionSource class.""" | ||
|
||
from .launch_description import LaunchDescription | ||
|
||
|
||
class LaunchDescriptionSource: | ||
"""Encapsulation of a launch description, where it comes from, and how it was generated.""" | ||
|
||
def __init__( | ||
self, | ||
launch_description: LaunchDescription, | ||
location: str = '<string>', | ||
method: str = 'unspecified mechanism from a script', | ||
) -> None: | ||
""" | ||
Constructor. | ||
For example, loading a file called ``example.launch.py`` for inclusion | ||
might end up setting `location` to ``/path/to/example.launch.py`` and | ||
the ``method`` to be ``interpreted python launch file``. | ||
:param launch_description: the launch description that this source represents | ||
:param location: the location from where this launch description was loaded if applicable | ||
:param method: the method by which the launch description was generated | ||
""" | ||
self.__launch_description = launch_description | ||
self.__location = location | ||
self.__method = method | ||
|
||
@property | ||
def launch_description(self) -> LaunchDescription: | ||
"""Getter for self.__launch_description.""" | ||
return self.__launch_description | ||
|
||
@property | ||
def location(self) -> str: | ||
"""Getter for self.__location.""" | ||
return self.__location | ||
|
||
@property | ||
def method(self) -> str: | ||
"""Getter for self.__method.""" | ||
return self.__method |
46 changes: 46 additions & 0 deletions
46
launch/test/launch/actions/test_include_launch_description.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,46 @@ | ||
# Copyright 2018 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. | ||
|
||
"""Tests for the IncludeLaunchDescription action class.""" | ||
|
||
from launch import LaunchDescription | ||
from launch import LaunchDescriptionSource | ||
from launch.actions import IncludeLaunchDescription | ||
|
||
|
||
def test_include_launch_description_constructors(): | ||
"""Test the constructors for IncludeLaunchDescription class.""" | ||
IncludeLaunchDescription(LaunchDescriptionSource(LaunchDescription())) | ||
|
||
|
||
def test_include_launch_description_methods(): | ||
"""Test the methods of the Action class.""" | ||
class MockLaunchContext: | ||
... | ||
|
||
ld = LaunchDescription() | ||
action = IncludeLaunchDescription(LaunchDescriptionSource(ld)) | ||
assert 'IncludeLaunchDescription' in action.describe() | ||
assert isinstance(action.describe_sub_entities(), list) | ||
assert isinstance(action.describe_conditional_sub_entities(), list) | ||
assert action.visit(MockLaunchContext()) == [ld] | ||
assert action.get_asyncio_future() is None | ||
|
||
ld2 = LaunchDescription([action]) | ||
action2 = IncludeLaunchDescription(LaunchDescriptionSource(ld2)) | ||
assert 'IncludeLaunchDescription' in action2.describe() | ||
assert isinstance(action2.describe_sub_entities(), list) | ||
assert isinstance(action2.describe_conditional_sub_entities(), list) | ||
assert action2.visit(MockLaunchContext()) == [ld2] | ||
assert action2.get_asyncio_future() is None |
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