File tree 4 files changed +46
-0
lines changed
4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ if(BUILD_TESTING)
53
53
msg/BuiltinTypeSequencesIdl.idl
54
54
msg/StringArrays.msg
55
55
msg/Property.msg
56
+ msg/Float.msg
56
57
ADD_LINTER_TESTS
57
58
SKIP_INSTALL
58
59
)
@@ -79,6 +80,12 @@ if(BUILD_TESTING)
79
80
APPEND_LIBRARY_DIRS "${_append_library_dirs} "
80
81
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_py"
81
82
)
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
+ )
82
89
endif ()
83
90
endif ()
84
91
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():
481
481
from collections .abc import ByteString
482
482
@ [ elif isinstance (type_, BasicType) and type_ .typename in CHARACTER_TYPES]@
483
483
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 (int)
484
488
@ [ end if ]@
485
489
assert \
486
490
@ [ 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
+ msg = Float ()
20
+
21
+ assert isinstance (msg .float_value , float )
22
+
23
+ # default value
24
+ assert 0 == msg .float_value
25
+
26
+ # set float value
27
+ msg .float_value = float (1 )
28
+
29
+ assert 1 == msg .float_value
30
+
31
+ # set int value, should not throw
32
+ msg .float_value = int (1 )
33
+
34
+ assert 1 == msg .float_value
You can’t perform that action at this time.
0 commit comments