File tree Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Expand file tree Collapse file tree 4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ if(BUILD_TESTING)
5353 msg/BuiltinTypeSequencesIdl.idl
5454 msg/StringArrays.msg
5555 msg/Property.msg
56+ msg/Float.msg
5657 ADD_LINTER_TESTS
5758 SKIP_INSTALL
5859 )
@@ -79,6 +80,12 @@ if(BUILD_TESTING)
7980 APPEND_LIBRARY_DIRS "${_append_library_dirs} "
8081 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_py"
8182 )
83+
84+ ament_add_pytest_test(test_int_to_float_py test /test_int_to_float.py
85+ APPEND_ENV "PYTHONPATH=${pythonpath} "
86+ APPEND_LIBRARY_DIRS "${_append_library_dirs} "
87+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_py"
88+ )
8289 endif ()
8390endif ()
8491
Original file line number Diff line number Diff line change 1+ float32 float_value
Original file line number Diff line number Diff line change @@ -481,6 +481,10 @@ if member.name in dict(inspect.getmembers(builtins)).keys():
481481 from collections .abc import ByteString
482482@ [ elif isinstance (type_, BasicType) and type_ .typename in CHARACTER_TYPES]@
483483 from collections import UserString
484+ @ [ end if ]@
485+ @ [ if isinstance (type_, BasicType) and type_ .typename in FLOATING_POINT_TYPES]@
486+ if isinstance (value, int):
487+ value = float (value)
484488@ [ end if ]@
485489 assert \
486490@ [ if isinstance (member .type , AbstractNestedType)]@
Original file line number Diff line number Diff line change 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 Float
16+
17+
18+ def test_int_to_float ():
19+ msg1 = Float (check_types = True , float_value = float (1 ))
20+
21+ assert isinstance (msg1 .float_value , float )
22+ assert 1 == msg1 .float_value
23+
24+ msg2 = Float (check_types = True , float_value = int (1 ))
25+ assert isinstance (msg2 .float_value , float )
26+ assert 1 == msg2 .float_value
You can’t perform that action at this time.
0 commit comments