Skip to content

Commit fb0eade

Browse files
author
Chen Lihui
authored
fix for msg file containing a property field that is not at the end (#151)
* fix for msg file containing a property field that is not at the end Signed-off-by: Chen Lihui <lihui.chen@sony.com> * add a test Signed-off-by: Chen Lihui <lihui.chen@sony.com>
1 parent f5eada7 commit fb0eade

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

rosidl_generator_py/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ if(BUILD_TESTING)
5757
${test_interface_files_MSG_FILES}
5858
# Cases not covered by test_interface_files
5959
msg/StringArrays.msg
60+
msg/Property.msg
6061
ADD_LINTER_TESTS
6162
SKIP_INSTALL
6263
)
@@ -80,6 +81,13 @@ if(BUILD_TESTING)
8081
ament_add_pytest_test(test_cli_extension test/test_cli_extension.py
8182
PYTHON_EXECUTABLE "${BUILDTYPE_PYTHON_EXECUTABLE}"
8283
)
84+
85+
ament_add_pytest_test(test_property_py test/test_property.py
86+
PYTHON_EXECUTABLE "${BUILDTYPE_PYTHON_EXECUTABLE}"
87+
APPEND_ENV "PYTHONPATH=${pythonpath}"
88+
APPEND_LIBRARY_DIRS "${_append_library_dirs}"
89+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py"
90+
)
8391
endif()
8492
endif()
8593

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
string property
2+
string anything

rosidl_generator_py/resource/_msg.py.em

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ if message.structure.members:
3636
imports.setdefault(
3737
'import rosidl_parser.definition', []) # used for SLOT_TYPES
3838
for member in message.structure.members:
39+
if member.name != EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME:
40+
imports.setdefault(
41+
'import builtins', []) # used for @builtins.property
3942
if (
4043
isinstance(member.type, AbstractNestedType) and
4144
isinstance(member.type.value_type, BasicType) and
@@ -405,7 +408,7 @@ noqa_string = ''
405408
if member.name in dict(inspect.getmembers(builtins)).keys():
406409
noqa_string = ' # noqa: A003'
407410
}@
408-
@@property@(noqa_string)
411+
@@builtins.property@(noqa_string)
409412
def @(member.name)(self):@(noqa_string)
410413
"""Message field '@(member.name)'."""
411414
return self._@(member.name)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from rosidl_generator_py.msg import Property
16+
17+
18+
def test_msg_property():
19+
msg = Property()
20+
21+
# types
22+
assert isinstance(msg.property, str)
23+
assert isinstance(msg.anything, str)
24+
25+
# default values
26+
assert '' == msg.property
27+
assert '' == msg.anything
28+
29+
# set values
30+
msg.property = 'a_value'
31+
msg.anything = 'another_value'
32+
33+
# get values
34+
assert 'a_value' == msg.property
35+
assert 'another_value' == msg.anything

0 commit comments

Comments
 (0)