From abce4dd5aa7c009cab11b19bf341993c5b546c38 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:10:06 -0400 Subject: [PATCH] Implement None check for ComposableNodeContainer (#341) (#371) (cherry picked from commit 35b2ca9f99f193bab82f02141300c6102e0bdb71) Co-authored-by: methylDragon --- .../actions/composable_node_container.py | 8 +++++--- .../actions/test_composable_node_container.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/launch_ros/launch_ros/actions/composable_node_container.py b/launch_ros/launch_ros/actions/composable_node_container.py index a7125e77..8740137e 100644 --- a/launch_ros/launch_ros/actions/composable_node_container.py +++ b/launch_ros/launch_ros/actions/composable_node_container.py @@ -80,9 +80,11 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]: """ load_actions = None # type: Optional[List[Action]] valid_composable_nodes = [] - for node_object in self.__composable_node_descriptions: - if node_object.condition() is None or node_object.condition().evaluate(context): - valid_composable_nodes.append(node_object) + if self.__composable_node_descriptions: + for node_object in self.__composable_node_descriptions: + if node_object.condition() is None or node_object.condition().evaluate(context): + valid_composable_nodes.append(node_object) + if ( valid_composable_nodes is not None and len(valid_composable_nodes) > 0 diff --git a/test_launch_ros/test/test_launch_ros/actions/test_composable_node_container.py b/test_launch_ros/test/test_launch_ros/actions/test_composable_node_container.py index 319734a5..2b091a93 100644 --- a/test_launch_ros/test/test_launch_ros/actions/test_composable_node_container.py +++ b/test_launch_ros/test/test_launch_ros/actions/test_composable_node_container.py @@ -89,6 +89,22 @@ def test_composable_node_container_empty_list_of_nodes(): assert get_node_name_count(context, f'/{TEST_NODE_NAMESPACE}/{TEST_NODE_NAME}') == 0 +def test_composable_node_container_no_list_of_nodes(): + """Test launching a ComposableNodeContainer with no passed in list of nodes.""" + actions = [ + ComposableNodeContainer( + package='rclcpp_components', + executable='component_container', + name=TEST_CONTAINER_NAME, + namespace=TEST_CONTAINER_NAMESPACE + ), + ] + + context = _assert_launch_no_errors(actions) + assert get_node_name_count(context, f'/{TEST_CONTAINER_NAMESPACE}/{TEST_CONTAINER_NAME}') == 1 + assert get_node_name_count(context, f'/{TEST_NODE_NAMESPACE}/{TEST_NODE_NAME}') == 0 + + def test_composable_node_container_in_group_with_launch_configuration_in_description(): """ Test launch configuration is passed to ComposableNode description inside GroupAction.