Skip to content

Commit d6589fd

Browse files
use new rosidl_parser.definition types and new test interfaces
Signed-off-by: Mikael Arguedas <[email protected]>
1 parent e2443ad commit d6589fd

File tree

4 files changed

+52
-57
lines changed

4 files changed

+52
-57
lines changed

rosidl_generator_py/test/test_interfaces.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727

2828
from rosidl_parser.definition import Array
2929
from rosidl_parser.definition import BoundedSequence
30+
from rosidl_parser.definition import BoundedString
3031
from rosidl_parser.definition import NamespacedType
31-
from rosidl_parser.definition import String
3232
from rosidl_parser.definition import UnboundedSequence
33+
from rosidl_parser.definition import UnboundedString
3334

3435

3536
def test_strings():
@@ -313,22 +314,22 @@ def test_slot_attributes():
313314
assert nested_slot_types[0].name == 'Primitives'
314315

315316
assert isinstance(nested_slot_types[1], Array)
316-
assert isinstance(nested_slot_types[1].basetype, NamespacedType)
317-
assert nested_slot_types[1].basetype.namespaces == \
317+
assert isinstance(nested_slot_types[1].value_type, NamespacedType)
318+
assert nested_slot_types[1].value_type.namespaces == \
318319
['rosidl_generator_py', 'msg']
319-
assert nested_slot_types[1].basetype.name == 'Primitives'
320+
assert nested_slot_types[1].value_type.name == 'Primitives'
320321

321322
assert isinstance(nested_slot_types[2], BoundedSequence)
322-
assert isinstance(nested_slot_types[2].basetype, NamespacedType)
323-
assert nested_slot_types[2].basetype.namespaces == \
323+
assert isinstance(nested_slot_types[2].value_type, NamespacedType)
324+
assert nested_slot_types[2].value_type.namespaces == \
324325
['rosidl_generator_py', 'msg']
325-
assert nested_slot_types[2].basetype.name == 'Primitives'
326+
assert nested_slot_types[2].value_type.name == 'Primitives'
326327

327328
assert isinstance(nested_slot_types[3], UnboundedSequence)
328-
assert isinstance(nested_slot_types[3].basetype, NamespacedType)
329-
assert nested_slot_types[3].basetype.namespaces == \
329+
assert isinstance(nested_slot_types[3].value_type, NamespacedType)
330+
assert nested_slot_types[3].value_type.namespaces == \
330331
['rosidl_generator_py', 'msg']
331-
assert nested_slot_types[3].basetype.name == 'Primitives'
332+
assert nested_slot_types[3].value_type.name == 'Primitives'
332333

333334

334335
def test_string_slot_attributes():
@@ -340,24 +341,22 @@ def test_string_slot_attributes():
340341
assert len(string_slot_types) == len(string_slots)
341342

342343
assert isinstance(string_slot_types[0], Array)
343-
assert isinstance(string_slot_types[0].basetype, String)
344+
assert isinstance(string_slot_types[0].value_type, BoundedString)
344345
assert string_slot_types[0].size == 3
345-
assert string_slot_types[0].basetype.maximum_size == 5
346+
assert string_slot_types[0].value_type.maximum_size == 5
346347

347348
assert isinstance(string_slot_types[1], BoundedSequence)
348-
assert isinstance(string_slot_types[1].basetype, String)
349-
assert string_slot_types[1].upper_bound == 10
350-
assert string_slot_types[1].basetype.maximum_size == 5
349+
assert isinstance(string_slot_types[1].value_type, BoundedString)
350+
assert string_slot_types[1].maximum_size == 10
351+
assert string_slot_types[1].value_type.maximum_size == 5
351352

352353
assert isinstance(string_slot_types[2], UnboundedSequence)
353-
assert isinstance(string_slot_types[2].basetype, String)
354-
assert string_slot_types[2].basetype.maximum_size == 5
354+
assert isinstance(string_slot_types[2].value_type, BoundedString)
355+
assert string_slot_types[2].value_type.maximum_size == 5
355356

356357
assert isinstance(string_slot_types[3], UnboundedSequence)
357-
assert isinstance(string_slot_types[3].basetype, String)
358-
assert string_slot_types[3].basetype.maximum_size is None
358+
assert isinstance(string_slot_types[3].value_type, UnboundedString)
359359

360360
assert isinstance(string_slot_types[4], Array)
361-
assert isinstance(string_slot_types[4].basetype, String)
361+
assert isinstance(string_slot_types[4].value_type, UnboundedString)
362362
assert string_slot_types[4].size == 3
363-
assert string_slot_types[4].basetype.maximum_size is None

rosidl_runtime_py/rosidl_runtime_py/import_message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
def import_message_from_namespaced_type(message_type: NamespacedType) -> Any:
2222
module = importlib.import_module(
23-
'.'.join(message_type.basetype.namespaces))
24-
return getattr(module, message_type.basetype.name)
23+
'.'.join(message_type.value_type.namespaces))
24+
return getattr(module, message_type.value_type.name)

rosidl_runtime_py/rosidl_runtime_py/set_message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from typing import Any
1616
from typing import Dict
1717

18+
from rosidl_parser.definition import AbstractNestedType
1819
from rosidl_parser.definition import NamespacedType
19-
from rosidl_parser.definition import NestedType
2020
from rosidl_runtime_py.convert import get_message_slot_types
2121
from rosidl_runtime_py.import_message import import_message_from_namespaced_type
2222

@@ -40,8 +40,8 @@ def set_message_fields(msg: Any, values: Dict[str, str]) -> None:
4040
set_message_fields(value, field_value)
4141
rosidl_type = get_message_slot_types(msg)[field_name]
4242
# Check if field is an array of ROS messages
43-
if isinstance(rosidl_type, NestedType):
44-
if isinstance(rosidl_type.basetype, NamespacedType):
43+
if isinstance(rosidl_type, AbstractNestedType):
44+
if isinstance(rosidl_type.value_type, NamespacedType):
4545
field_elem_type = import_message_from_namespaced_type(rosidl_type)
4646
for n in range(len(value)):
4747
submsg = field_elem_type()

rosidl_runtime_py/test/rosidl_runtime_py/test_set_message.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,40 +94,36 @@ def test_set_message_fields_invalid():
9494

9595

9696
def test_set_nested_namespaced_fields():
97-
msg = message_fixtures.get_msg_dynamic_array_nested()[0]
97+
unbounded_sequence_msg = message_fixtures.get_msg_unbounded_sequences()[1]
9898
test_values = {
99-
'primitive_values': [
100-
{'string_value': 'foo', 'int8_value': 42},
101-
{'string_value': 'bar', 'int8_value': 11}
99+
'basic_types_values': [
100+
{'float64_value': 42.42, 'int8_value': 42},
101+
{'float64_value': 11.11, 'int8_value': 11}
102102
]
103103
}
104-
set_message_fields(msg, test_values)
105-
assert msg.primitive_values[0].string_value == 'foo'
106-
assert msg.primitive_values[0].int8_value == 42
107-
assert msg.primitive_values[0].uint8_value == 0
108-
assert msg.primitive_values[1].string_value == 'bar'
109-
assert msg.primitive_values[1].int8_value == 11
110-
assert msg.primitive_values[1].uint8_value == 0
111-
112-
static_array_msg = message_fixtures.get_msg_static_array_nested()[0]
104+
set_message_fields(unbounded_sequence_msg, test_values)
105+
assert unbounded_sequence_msg.basic_types_values[0].float64_value == 42.42
106+
assert unbounded_sequence_msg.basic_types_values[0].int8_value == 42
107+
assert unbounded_sequence_msg.basic_types_values[0].uint8_value == 0
108+
assert unbounded_sequence_msg.basic_types_values[1].float64_value == 11.11
109+
assert unbounded_sequence_msg.basic_types_values[1].int8_value == 11
110+
assert unbounded_sequence_msg.basic_types_values[1].uint8_value == 0
111+
112+
arrays_msg = message_fixtures.get_msg_arrays()[0]
113113
test_values = {
114-
'primitive_values': [
115-
{'string_value': 'foo', 'int8_value': 42},
116-
{'string_value': 'bar', 'int8_value': 11},
117-
{'string_value': 'baz', 'int8_value': 22},
118-
{'string_value': 'foobar', 'int8_value': 33}
114+
'basic_types_values': [
115+
{'float64_value': 42.42, 'int8_value': 42},
116+
{'float64_value': 11.11, 'int8_value': 11},
117+
{'float64_value': 22.22, 'int8_value': 22},
119118
]
120119
}
121-
set_message_fields(static_array_msg, test_values)
122-
assert static_array_msg.primitive_values[0].string_value == 'foo'
123-
assert static_array_msg.primitive_values[0].int8_value == 42
124-
assert static_array_msg.primitive_values[0].uint8_value == 0
125-
assert static_array_msg.primitive_values[1].string_value == 'bar'
126-
assert static_array_msg.primitive_values[1].int8_value == 11
127-
assert static_array_msg.primitive_values[1].uint8_value == 0
128-
assert static_array_msg.primitive_values[2].string_value == 'baz'
129-
assert static_array_msg.primitive_values[2].int8_value == 22
130-
assert static_array_msg.primitive_values[2].uint8_value == 0
131-
assert static_array_msg.primitive_values[3].string_value == 'foobar'
132-
assert static_array_msg.primitive_values[3].int8_value == 33
133-
assert static_array_msg.primitive_values[3].uint8_value == 0
120+
set_message_fields(arrays_msg, test_values)
121+
assert arrays_msg.basic_types_values[0].float64_value == 42.42
122+
assert arrays_msg.basic_types_values[0].int8_value == 42
123+
assert arrays_msg.basic_types_values[0].uint8_value == 0
124+
assert arrays_msg.basic_types_values[1].float64_value == 11.11
125+
assert arrays_msg.basic_types_values[1].int8_value == 11
126+
assert arrays_msg.basic_types_values[1].uint8_value == 0
127+
assert arrays_msg.basic_types_values[2].float64_value == 22.22
128+
assert arrays_msg.basic_types_values[2].int8_value == 22
129+
assert arrays_msg.basic_types_values[2].uint8_value == 0

0 commit comments

Comments
 (0)