|
16 | 16 |
|
17 | 17 | import numpy |
18 | 18 | import pytest |
| 19 | + |
19 | 20 | from rosidl_generator_py.msg import Constants |
20 | 21 | from rosidl_generator_py.msg import Nested |
21 | 22 | from rosidl_generator_py.msg import Primitives |
|
24 | 25 | from rosidl_generator_py.msg import Various |
25 | 26 | from rosidl_generator_py.msg import WStrings |
26 | 27 |
|
| 28 | +from rosidl_parser.definition import Array |
| 29 | +from rosidl_parser.definition import BoundedSequence |
| 30 | +from rosidl_parser.definition import BoundedString |
| 31 | +from rosidl_parser.definition import NamespacedType |
| 32 | +from rosidl_parser.definition import UnboundedSequence |
| 33 | +from rosidl_parser.definition import UnboundedString |
| 34 | + |
27 | 35 |
|
28 | 36 | def test_strings(): |
29 | 37 | a = Strings() |
@@ -314,7 +322,7 @@ def test_slot_attributes(): |
314 | 322 | assert expected_slot_type == nested_slot_types_dict[expected_field] |
315 | 323 |
|
316 | 324 |
|
317 | | -def test_primative_slot_attributes(): |
| 325 | +def test_string_slot_attributes(): |
318 | 326 | b = StringArrays() |
319 | 327 | assert hasattr(b, 'get_fields_and_field_types') |
320 | 328 | assert hasattr(b, '__slots__') |
@@ -349,3 +357,63 @@ def test_modifying_slot_fields_and_types(): |
349 | 357 | string_slot_types_dict_len = len(string_slot_types_dict) |
350 | 358 | string_slot_types_dict[1] = 2 |
351 | 359 | assert len(getattr(b, 'get_fields_and_field_types')()) == string_slot_types_dict_len |
| 360 | + |
| 361 | + |
| 362 | +def test_slot_types(): |
| 363 | + a = Nested() |
| 364 | + assert hasattr(a, 'SLOT_TYPES') |
| 365 | + assert hasattr(a, '__slots__') |
| 366 | + nested_slot_types = Nested.SLOT_TYPES |
| 367 | + nested_slots = getattr(a, '__slots__') |
| 368 | + assert len(nested_slot_types) == len(nested_slots) |
| 369 | + assert isinstance(nested_slot_types[0], NamespacedType) |
| 370 | + assert nested_slot_types[0].namespaces == ['rosidl_generator_py', 'msg'] |
| 371 | + assert nested_slot_types[0].name == 'Primitives' |
| 372 | + |
| 373 | + assert isinstance(nested_slot_types[1], Array) |
| 374 | + assert isinstance(nested_slot_types[1].value_type, NamespacedType) |
| 375 | + assert nested_slot_types[1].value_type.namespaces == \ |
| 376 | + ['rosidl_generator_py', 'msg'] |
| 377 | + assert nested_slot_types[1].value_type.name == 'Primitives' |
| 378 | + |
| 379 | + assert isinstance(nested_slot_types[2], BoundedSequence) |
| 380 | + assert isinstance(nested_slot_types[2].value_type, NamespacedType) |
| 381 | + assert nested_slot_types[2].value_type.namespaces == \ |
| 382 | + ['rosidl_generator_py', 'msg'] |
| 383 | + assert nested_slot_types[2].value_type.name == 'Primitives' |
| 384 | + |
| 385 | + assert isinstance(nested_slot_types[3], UnboundedSequence) |
| 386 | + assert isinstance(nested_slot_types[3].value_type, NamespacedType) |
| 387 | + assert nested_slot_types[3].value_type.namespaces == \ |
| 388 | + ['rosidl_generator_py', 'msg'] |
| 389 | + assert nested_slot_types[3].value_type.name == 'Primitives' |
| 390 | + |
| 391 | + |
| 392 | +def test_string_slot_types(): |
| 393 | + b = StringArrays() |
| 394 | + assert hasattr(b, 'SLOT_TYPES') |
| 395 | + assert hasattr(b, '__slots__') |
| 396 | + string_slot_types = StringArrays.SLOT_TYPES |
| 397 | + string_slots = getattr(b, '__slots__') |
| 398 | + assert len(string_slot_types) == len(string_slots) |
| 399 | + |
| 400 | + assert isinstance(string_slot_types[0], Array) |
| 401 | + assert isinstance(string_slot_types[0].value_type, BoundedString) |
| 402 | + assert string_slot_types[0].size == 3 |
| 403 | + assert string_slot_types[0].value_type.maximum_size == 5 |
| 404 | + |
| 405 | + assert isinstance(string_slot_types[1], BoundedSequence) |
| 406 | + assert isinstance(string_slot_types[1].value_type, BoundedString) |
| 407 | + assert string_slot_types[1].maximum_size == 10 |
| 408 | + assert string_slot_types[1].value_type.maximum_size == 5 |
| 409 | + |
| 410 | + assert isinstance(string_slot_types[2], UnboundedSequence) |
| 411 | + assert isinstance(string_slot_types[2].value_type, BoundedString) |
| 412 | + assert string_slot_types[2].value_type.maximum_size == 5 |
| 413 | + |
| 414 | + assert isinstance(string_slot_types[3], UnboundedSequence) |
| 415 | + assert isinstance(string_slot_types[3].value_type, UnboundedString) |
| 416 | + |
| 417 | + assert isinstance(string_slot_types[4], Array) |
| 418 | + assert isinstance(string_slot_types[4].value_type, UnboundedString) |
| 419 | + assert string_slot_types[4].size == 3 |
0 commit comments