@@ -303,6 +303,63 @@ def test_out_of_range():
303303
304304
305305def test_slot_attributes ():
306+ a = Nested ()
307+ assert hasattr (a , 'get_fields_and_field_types' )
308+ assert hasattr (a , '__slots__' )
309+ nested_slot_types_dict = getattr (a , 'get_fields_and_field_types' )()
310+ nested_slots = getattr (a , '__slots__' )
311+ assert len (nested_slot_types_dict ) == len (nested_slots )
312+ expected_nested_slot_types_dict = {
313+ 'primitives' : 'rosidl_generator_py/Primitives' ,
314+ 'two_primitives' : 'rosidl_generator_py/Primitives[2]' ,
315+ 'up_to_three_primitives' : 'sequence<rosidl_generator_py/Primitives, 3>' ,
316+ 'unbounded_primitives' : 'sequence<rosidl_generator_py/Primitives>' ,
317+ }
318+ assert len (nested_slot_types_dict ) == len (expected_nested_slot_types_dict )
319+
320+ for expected_field , expected_slot_type in expected_nested_slot_types_dict .items ():
321+ assert expected_field in nested_slot_types_dict .keys ()
322+ assert expected_slot_type == nested_slot_types_dict [expected_field ]
323+
324+
325+ def test_string_slot_attributes ():
326+ b = StringArrays ()
327+ assert hasattr (b , 'get_fields_and_field_types' )
328+ assert hasattr (b , '__slots__' )
329+ string_slot_types_dict = getattr (b , 'get_fields_and_field_types' )()
330+ string_slots = getattr (b , '__slots__' )
331+ assert len (string_slot_types_dict ) == len (string_slots )
332+ expected_string_slot_types_dict = {
333+ 'ub_string_static_array_value' : 'string<5>[3]' ,
334+ 'ub_string_ub_array_value' : 'sequence<string<5>, 10>' ,
335+ 'ub_string_dynamic_array_value' : 'sequence<string<5>>' ,
336+ 'string_dynamic_array_value' : 'sequence<string>' ,
337+ 'string_static_array_value' : 'string[3]' ,
338+ 'string_bounded_array_value' : 'sequence<string, 10>' ,
339+ 'def_string_dynamic_array_value' : 'sequence<string>' ,
340+ 'def_string_static_array_value' : 'string[3]' ,
341+ 'def_string_bounded_array_value' : 'sequence<string, 10>' ,
342+ 'def_various_quotes' : 'sequence<string>' ,
343+ 'def_various_commas' : 'sequence<string>' ,
344+ }
345+
346+ assert len (string_slot_types_dict ) == len (expected_string_slot_types_dict )
347+
348+ for expected_field , expected_slot_type in expected_string_slot_types_dict .items ():
349+ assert expected_field in string_slot_types_dict .keys ()
350+ assert expected_slot_type == string_slot_types_dict [expected_field ]
351+
352+
353+ def test_modifying_slot_fields_and_types ():
354+ b = StringArrays ()
355+ assert hasattr (b , 'get_fields_and_field_types' )
356+ string_slot_types_dict = getattr (b , 'get_fields_and_field_types' )()
357+ string_slot_types_dict_len = len (string_slot_types_dict )
358+ string_slot_types_dict [1 ] = 2
359+ assert len (getattr (b , 'get_fields_and_field_types' )()) == string_slot_types_dict_len
360+
361+
362+ def test_slot_types ():
306363 a = Nested ()
307364 assert hasattr (a , 'SLOT_TYPES' )
308365 assert hasattr (a , '__slots__' )
@@ -332,7 +389,7 @@ def test_slot_attributes():
332389 assert nested_slot_types [3 ].value_type .name == 'Primitives'
333390
334391
335- def test_string_slot_attributes ():
392+ def test_string_slot_types ():
336393 b = StringArrays ()
337394 assert hasattr (b , 'SLOT_TYPES' )
338395 assert hasattr (b , '__slots__' )
0 commit comments