Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions launch_ros/launch_ros/actions/push_ros_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from launch.substitutions import SubstitutionFailure
from launch.utilities import normalize_to_list_of_substitutions
from launch.utilities import perform_substitutions
from launch.utilities import register_global

from launch_ros.utilities import make_namespace_absolute
from launch_ros.utilities import prefix_namespace
Expand Down Expand Up @@ -79,4 +80,5 @@ def execute(self, context: LaunchContext):
previous_namespace, pushed_namespace
)
)
register_global(context, 'ros_namespace')
context.launch_configurations['ros_namespace'] = namespace
2 changes: 2 additions & 0 deletions launch_ros/launch_ros/actions/set_remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from launch.some_substitutions_type import SomeSubstitutionsType
from launch.utilities import normalize_to_list_of_substitutions
from launch.utilities import perform_substitutions
from launch.utilities import register_global


@expose_action('set_remap')
Expand Down Expand Up @@ -90,4 +91,5 @@ def execute(self, context: LaunchContext):
dst = perform_substitutions(context, self.__dst)
global_remaps = context.launch_configurations.get('ros_remaps', [])
global_remaps.append((src, dst))
register_global(context, 'ros_remaps')
context.launch_configurations['ros_remaps'] = global_remaps
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

"""Tests for the PushROSNamespace Action."""

from typing import Any
from typing import Dict
from typing import Text

from launch_ros.actions import Node
from launch_ros.actions import PushROSNamespace
from launch_ros.actions.load_composable_nodes import get_composable_node_load_request
Expand All @@ -26,10 +30,38 @@ class MockContext:

def __init__(self):
self.launch_configurations = {}
self.__locals = {}

def perform_substitution(self, sub):
return sub.perform(None)

@property # noqa: A003
def locals(self): # noqa: A003
"""Getter for the locals."""
class AttributeDict:

def __init__(self, dict_in):
self.__dict__['__dict'] = dict_in

def __getattr__(self, key):
_dict = self.__dict__['__dict']
if key not in _dict:
raise AttributeError(
"context.locals does not contain attribute '{}', it contains: [{}]".format(
key,
', '.join(_dict.keys())
)
)
return _dict[key]

def __setattr__(self, key, value):
raise AttributeError("can't set attribute '{}', locals are read-only".format(key))

return AttributeDict(self.__locals)

def extend_locals(self, extension: Dict[Text, Any]) -> None:
self.__locals.update(extension)


class Config:

Expand Down
32 changes: 32 additions & 0 deletions test_launch_ros/test/test_launch_ros/actions/test_set_remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

"""Tests for the SetRemap Action."""

from typing import Any
from typing import Dict
from typing import Text

from launch import LaunchContext
from launch.actions import PopLaunchConfigurations
from launch.actions import PushLaunchConfigurations
Expand All @@ -30,10 +34,38 @@ class MockContext:

def __init__(self):
self.launch_configurations = {}
self.__locals = {}

def perform_substitution(self, sub):
return sub.perform(None)

@property # noqa: A003
def locals(self): # noqa: A003
"""Getter for the locals."""
class AttributeDict:

def __init__(self, dict_in):
self.__dict__['__dict'] = dict_in

def __getattr__(self, key):
_dict = self.__dict__['__dict']
if key not in _dict:
raise AttributeError(
"context.locals does not contain attribute '{}', it contains: [{}]".format(
key,
', '.join(_dict.keys())
)
)
return _dict[key]

def __setattr__(self, key, value):
raise AttributeError("can't set attribute '{}', locals are read-only".format(key))

return AttributeDict(self.__locals)

def extend_locals(self, extension: Dict[Text, Any]) -> None:
self.__locals.update(extension)


def get_set_remap_test_remaps():
return [
Expand Down