Skip to content

Commit

Permalink
handle set_message_fields given some non-basic type (#68)
Browse files Browse the repository at this point in the history
Fix #67

Signed-off-by: artivis <jeremie.deray@canonical.com>
  • Loading branch information
artivis authored and jacobperron committed Jul 12, 2019
1 parent 3a1bb97 commit 2d8af1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rosidl_runtime_py/rosidl_runtime_py/set_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def set_message_fields(msg: Any, values: Dict[str, str]) -> None:
field_type = type(field)
if field_type is array.array:
value = field_type(field.typecode, field_value)
elif type(field_value) is field_type:
value = field_value
else:
try:
value = field_type(field_value)
Expand Down
17 changes: 17 additions & 0 deletions rosidl_runtime_py/test/rosidl_runtime_py/test_set_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,20 @@ def test_set_nested_namespaced_fields():
assert arrays_msg.basic_types_values[2].float64_value == 22.22
assert arrays_msg.basic_types_values[2].int8_value == 22
assert arrays_msg.basic_types_values[2].uint8_value == 0


def test_set_message_fields_nested_type():
msg_basic_types = message_fixtures.get_msg_basic_types()[0]
msg0 = message_fixtures.get_msg_nested()[0]

msg0.basic_types_value.bool_value = False
msg0.basic_types_value.char_value = 3
msg0.basic_types_value.int32_value = 42

assert msg0.basic_types_value != msg_basic_types

test_values = {}
test_values['basic_types_value'] = msg_basic_types
set_message_fields(msg0, test_values)

assert msg0.basic_types_value == msg_basic_types

0 comments on commit 2d8af1e

Please sign in to comment.