Skip to content
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

Make namespace parameter mandatory in LifecycleNode constructor #157

Merged
merged 8 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions launch_ros/launch_ros/actions/lifecycle_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import warnings

import launch
from launch import SomeSubstitutionsType
from launch.action import Action
import launch.logging

Expand All @@ -42,8 +43,9 @@ class LifecycleNode(Node):
def __init__(
self,
*,
name: Optional[Text] = None,
node_name: Optional[Text] = None,
name: Optional[SomeSubstitutionsType] = None,
namespace: SomeSubstitutionsType = '',
node_name: Optional[SomeSubstitutionsType] = None,
sloretz marked this conversation as resolved.
Show resolved Hide resolved
hidmic marked this conversation as resolved.
Show resolved Hide resolved
**kwargs
) -> None:
"""
Expand Down Expand Up @@ -87,7 +89,7 @@ def __init__(
# TODO(jacobperron): Remove default value and this check when deprecated API is removed
if name is None:
raise RuntimeError("'name' must not be None.'")
super().__init__(name=name, **kwargs)
super().__init__(name=name, namespace=namespace, **kwargs)
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
self.__logger = launch.logging.get_logger(__name__)
self.__rclpy_subscription = None
self.__current_state = \
Expand Down
31 changes: 29 additions & 2 deletions test_launch_ros/test/test_launch_ros/actions/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def _assert_launch_no_errors(self, actions):
def _create_node(self, *, parameters=None, remappings=None):
return launch_ros.actions.Node(
package='demo_nodes_py', executable='talker_qos', output='screen',
# The node name is required for parameter dicts.
# See https://github.com/ros2/launch/issues/139.
name='my_node', namespace='my_ns',
exec_name='my_node_process',
arguments=['--number_of_cycles', '1'],
Expand Down Expand Up @@ -300,3 +298,32 @@ def test_launch_node_with_invalid_parameter_dicts(self):
},
},
}])

def test_node_name():
node_without_ns = launch_ros.actions.Node(
package='asd',
executable='bsd',
name='my_node',
)
lc = launch.LaunchContext()
node_without_ns._perform_substitutions(context)
assert not node.is_node_name_fully_specified()

node_without_name = launch_ros.actions.Node(
package='asd',
executable='bsd',
namespace='my_ns',
)
lc = launch.LaunchContext()
node_without_ns._perform_substitutions(context)
assert not node.is_node_name_fully_specified()

node_with_fqn = launch_ros.actions.Node(
package='asd',
executable='bsd',
name='my_node',
namespace='my_ns',
)
lc = launch.LaunchContext()
node_without_ns._perform_substitutions(context)
assert node.is_node_name_fully_specified()