Skip to content
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
17 changes: 7 additions & 10 deletions src/roswire/definitions/srv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = ['SrvFormat']
# -*- coding: utf-8 -*-
__all__ = ('SrvFormat',)

from typing import Optional, List, Dict, Any
import os
Expand All @@ -20,8 +21,7 @@ class SrvFormat:

@staticmethod
def from_file(package: str, fn: str, files: FileProxy) -> 'SrvFormat':
"""
Constructs a service format from a .srv file for a given package.
"""Constructs a service format from a .srv file for a given package.

Parameters:
package: the name of the package that provides the file.
Expand All @@ -38,8 +38,7 @@ def from_file(package: str, fn: str, files: FileProxy) -> 'SrvFormat':

@staticmethod
def from_string(package: str, name: str, s: str) -> 'SrvFormat':
"""
Constructs a service format from its description.
"""Constructs a service format from its description.

Raises:
ParsingError: if the description cannot be parsed.
Expand All @@ -50,11 +49,9 @@ def from_string(package: str, name: str, s: str) -> 'SrvFormat':
name_res = f"{name}Response"

sections: List[str] = [ss.strip() for ss in s.split('---')]
try:
s_req, s_res = sections
except ValueError:
m = "bad service description: missing separator (---)"
raise exceptions.ParsingError(m)
assert len(sections) < 3
s_req = sections[0]
s_res = sections[1] if len(sections) > 1 else ''

if s_req:
req = MsgFormat.from_string(package, name_req, s_req)
Expand Down
8 changes: 7 additions & 1 deletion test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ def test_srv_from_string():

assert len(res.fields) == 3
assert Field('another_pkg/YetAnotherMessage', 'val') in res.fields
assert Field('CustomMessageDefinedInThisPackage', 'value') in res.fields
assert Field('PkgName/CustomMessageDefinedInThisPackage', 'value') in res.fields
assert Field('uint32', 'an_integer') in res.fields

# bug #269
s = "map_msgs/ProjectedMapInfo[] projected_maps_info"
fmt = SrvFormat.from_string("map_msgs", "ProjectedMapsInfo", s)
assert fmt.request is not None
assert fmt.response is None


def test_action_from_string():
s = """
Expand Down