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

[ros2action] Remove show verb #405

Merged
merged 3 commits into from
Dec 2, 2019
Merged
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
51 changes: 5 additions & 46 deletions ros2action/ros2action/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python import get_resource
from ament_index_python import get_resources
from ament_index_python import has_resource

import rclpy.action
from rclpy.expand_topic_name import expand_topic_name
from rclpy.validate_full_topic_name import validate_full_topic_name
from ros2cli.node.direct import DirectNode
from rosidl_runtime_py.convert import message_to_yaml
from rosidl_runtime_py import get_action_interfaces
from rosidl_runtime_py import message_to_yaml
from rosidl_runtime_py.utilities import get_action


Expand Down Expand Up @@ -74,40 +69,6 @@ def get_action_names(*, node):
return [n for (n, t) in action_names_and_types]


def get_action_types(package_name):
if not has_resource('packages', package_name):
raise LookupError('Unknown package name')
try:
content, _ = get_resource('rosidl_interfaces', package_name)
except LookupError:
return []
interface_names = content.splitlines()
# TODO(jacobperron) this logic should come from a rosidl related package
# Only return actions in action folder
return {
n[7:-7]
for n in interface_names
if n.startswith('action/') and n[-7:] in ('.idl', '.action')}


def get_all_action_types():
all_action_types = {}
for package_name in get_resources('rosidl_interfaces'):
action_types = get_action_types(package_name)
if action_types:
all_action_types[package_name] = action_types
return all_action_types


def get_action_path(package_name, action_name):
action_types = get_action_types(package_name)
if action_name not in action_types:
raise LookupError('Unknown action type')
prefix_path = has_resource('packages', package_name)
# TODO(jacobperron) this logic should come from a rosidl related package
return os.path.join(prefix_path, 'share', package_name, 'action', action_name + '.action')


def action_name_completer(prefix, parsed_args, **kwargs):
"""Callable returning a list of action names."""
with DirectNode(parsed_args) as node:
Expand All @@ -117,11 +78,9 @@ def action_name_completer(prefix, parsed_args, **kwargs):
def action_type_completer(**kwargs):
"""Callable returning a list of action types."""
action_types = []
action_types_dict = get_all_action_types()
for package_name in sorted(action_types_dict.keys()):
for action_name in sorted(action_types_dict[package_name]):
action_types.append(
'{package_name}/action/{action_name}'.format_map(locals()))
for package_name, action_names in get_action_interfaces.items():
for action_name in action_names:
action_types.append(f'{package_name}/{action_name}')
return action_types


Expand Down
48 changes: 0 additions & 48 deletions ros2action/ros2action/verb/show.py

This file was deleted.

1 change: 0 additions & 1 deletion ros2action/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
'info = ros2action.verb.info:InfoVerb',
'list = ros2action.verb.list:ListVerb',
'send_goal = ros2action.verb.send_goal:SendGoalVerb',
'show = ros2action.verb.show:ShowVerb',
],
}
)
28 changes: 0 additions & 28 deletions ros2action/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import pytest

from ros2action.api import get_action_clients_and_servers
from ros2action.api import get_action_names
from ros2action.api import get_action_path
from ros2action.api import get_action_types
from ros2cli.node.strategy import DirectNode


Expand All @@ -36,25 +30,3 @@ def test_get_action_clients_and_servers():
def test_get_action_names():
with DirectNode(None) as node:
get_action_names(node=node)


def test_get_action_path():
action_path = get_action_path('test_msgs', 'Fibonacci')
assert os.path.isfile(action_path)

with pytest.raises(LookupError):
get_action_path('_not_a_real_package_name', 'Fibonacci')


def test_get_action_types():
action_types = get_action_types('test_msgs')
# Expect only strings
for t in action_types:
assert isinstance(t, str)
# Explicit dependencies of this package should be available
assert 'Fibonacci' in action_types
assert 'NestedMessage' in action_types
# Some things that should not be in the list
assert '' not in action_types
assert 'test_msgs' not in action_types
assert 'NotAnActionMessage' not in action_types
63 changes: 0 additions & 63 deletions ros2action/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,66 +248,3 @@ def test_send_fibonacci_goal_with_feedback(self):
),
text=action_command.output, strict=True
)

def test_show_fibonacci(self):
with self.launch_action_command(
arguments=['show', 'test_msgs/action/Fibonacci'],
) as action_command:
assert action_command.wait_for_shutdown(timeout=2)
assert action_command.exit_code == launch_testing.asserts.EXIT_OK
assert launch_testing.tools.expect_output(
expected_lines=[
'int32 order',
'---',
'int32[] sequence',
'---',
'int32[] sequence'
],
text=action_command.output,
strict=False
)

def test_show_not_a_package(self):
with self.launch_action_command(
arguments=['show', 'not_a_package/action/Fibonacci'],
) as action_command:
assert action_command.wait_for_shutdown(timeout=2)
assert action_command.exit_code == 1
assert launch_testing.tools.expect_output(
expected_lines=['Unknown package name'],
text=action_command.output, strict=True
)

# TODO(hidmic): make 'ros2 action show' fail accordingly
# def test_show_not_an_action_ns(self):
# with self.launch_action_command(
# arguments=['show', 'test_msgs/foo/Fibonacci'],
# ) as action_command:
# assert action_command.wait_for_shutdown(timeout=2)
# assert action_command.exit_code == 1
# assert launch_testing.tools.expect_output(
# expected_lines=['Unknown action type'],
# text=action_command.output, strict=True
# )

def test_show_not_an_action_typename(self):
with self.launch_action_command(
arguments=['show', 'test_msgs/action/NotAnActionTypeName'],
) as action_command:
assert action_command.wait_for_shutdown(timeout=2)
assert action_command.exit_code == 1
assert launch_testing.tools.expect_output(
expected_lines=['Unknown action type'],
text=action_command.output, strict=True
)

def test_show_not_an_action_type(self):
with self.launch_action_command(
arguments=['show', 'not_an_action_type']
) as action_command:
assert action_command.wait_for_shutdown(timeout=2)
assert action_command.exit_code == 1
assert launch_testing.tools.expect_output(
expected_lines=['The passed action type is invalid'],
text=action_command.output, strict=True
)