From 0271e5675645faeffb3a4aa99a35e4524d1b7a73 Mon Sep 17 00:00:00 2001 From: Mikael Arguedas Date: Sat, 16 Mar 2019 14:24:52 +0100 Subject: [PATCH] update tests and remove coverage for dict to avoid circular dependency Signed-off-by: Mikael Arguedas --- rosidl_generator_py/test/test_interfaces.py | 109 +++++++------------- 1 file changed, 38 insertions(+), 71 deletions(-) diff --git a/rosidl_generator_py/test/test_interfaces.py b/rosidl_generator_py/test/test_interfaces.py index d0650cb7..f9bfaf85 100644 --- a/rosidl_generator_py/test/test_interfaces.py +++ b/rosidl_generator_py/test/test_interfaces.py @@ -276,43 +276,31 @@ def test_slot_attributes(): from rosidl_parser.definition import UnboundedSequence a = Nested() assert hasattr(a, 'SLOT_TYPES') - assert hasattr(a, 'get_slot_types') assert hasattr(a, '__slots__') - nested_slot_types_dict = getattr(a, 'get_slot_types')() nested_slot_types = Nested.SLOT_TYPES nested_slots = getattr(a, '__slots__') - assert len(nested_slot_types_dict) == len(nested_slots) assert len(nested_slot_types) == len(nested_slots) - expected_keys = [ - 'primitives', - 'two_primitives', - 'up_to_three_primitives', - 'unbounded_primitives', - ] - assert len(nested_slot_types_dict.keys()) == len(expected_keys) - for e_key in expected_keys: - assert e_key in nested_slot_types_dict.keys() - assert isinstance(nested_slot_types_dict['primitives'], NamespacedType) - assert nested_slot_types_dict['primitives'].namespaces == ['rosidl_generator_py', 'msg'] - assert nested_slot_types_dict['primitives'].name == 'Primitives' - - assert isinstance(nested_slot_types_dict['two_primitives'], Array) - assert isinstance(nested_slot_types_dict['two_primitives'].basetype, NamespacedType) - assert nested_slot_types_dict['two_primitives'].basetype.namespaces == \ + assert isinstance(nested_slot_types[0], NamespacedType) + assert nested_slot_types[0].namespaces == ['rosidl_generator_py', 'msg'] + assert nested_slot_types[0].name == 'Primitives' + + assert isinstance(nested_slot_types[1], Array) + assert isinstance(nested_slot_types[1].basetype, NamespacedType) + assert nested_slot_types[1].basetype.namespaces == \ ['rosidl_generator_py', 'msg'] - assert nested_slot_types_dict['two_primitives'].basetype.name == 'Primitives' + assert nested_slot_types[1].basetype.name == 'Primitives' - assert isinstance(nested_slot_types_dict['up_to_three_primitives'], BoundedSequence) - assert isinstance(nested_slot_types_dict['up_to_three_primitives'].basetype, NamespacedType) - assert nested_slot_types_dict['up_to_three_primitives'].basetype.namespaces == \ + assert isinstance(nested_slot_types[2], BoundedSequence) + assert isinstance(nested_slot_types[2].basetype, NamespacedType) + assert nested_slot_types[2].basetype.namespaces == \ ['rosidl_generator_py', 'msg'] - assert nested_slot_types_dict['up_to_three_primitives'].basetype.name == 'Primitives' + assert nested_slot_types[2].basetype.name == 'Primitives' - assert isinstance(nested_slot_types_dict['unbounded_primitives'], UnboundedSequence) - assert isinstance(nested_slot_types_dict['unbounded_primitives'].basetype, NamespacedType) - assert nested_slot_types_dict['unbounded_primitives'].basetype.namespaces == \ + assert isinstance(nested_slot_types[3], UnboundedSequence) + assert isinstance(nested_slot_types[3].basetype, NamespacedType) + assert nested_slot_types[3].basetype.namespaces == \ ['rosidl_generator_py', 'msg'] - assert nested_slot_types_dict['unbounded_primitives'].basetype.name == 'Primitives' + assert nested_slot_types[3].basetype.name == 'Primitives' def test_string_slot_attributes(): @@ -322,51 +310,30 @@ def test_string_slot_attributes(): from rosidl_parser.definition import UnboundedSequence b = StringArrays() assert hasattr(b, 'SLOT_TYPES') - assert hasattr(b, 'get_slot_types') assert hasattr(b, '__slots__') - string_slot_types_dict = getattr(b, 'get_slot_types')() string_slot_types = StringArrays.SLOT_TYPES string_slots = getattr(b, '__slots__') - assert len(string_slot_types_dict) == len(string_slots) assert len(string_slot_types) == len(string_slots) - expected_keys = [ - 'ub_string_static_array_value', - 'ub_string_ub_array_value', - 'ub_string_dynamic_array_value', - 'string_dynamic_array_value', - 'string_static_array_value', - 'string_bounded_array_value', - 'def_string_dynamic_array_value', - 'def_string_static_array_value', - 'def_string_bounded_array_value', - 'def_various_quotes', - 'def_various_commas', - ] - - assert len(string_slot_types_dict.keys()) == len(expected_keys) - for e_key in expected_keys: - assert e_key in string_slot_types_dict.keys() - - assert isinstance(string_slot_types_dict['ub_string_static_array_value'], Array) - assert isinstance(string_slot_types_dict['ub_string_static_array_value'].basetype, String) - assert string_slot_types_dict['ub_string_static_array_value'].size == 3 - assert string_slot_types_dict['ub_string_static_array_value'].basetype.maximum_size == '5' - - assert isinstance(string_slot_types_dict['ub_string_ub_array_value'], BoundedSequence) - assert isinstance(string_slot_types_dict['ub_string_ub_array_value'].basetype, String) - assert string_slot_types_dict['ub_string_ub_array_value'].upper_bound == 10 - assert string_slot_types_dict['ub_string_ub_array_value'].basetype.maximum_size == '5' - - assert isinstance(string_slot_types_dict['ub_string_dynamic_array_value'], UnboundedSequence) - assert isinstance(string_slot_types_dict['ub_string_dynamic_array_value'].basetype, String) - assert string_slot_types_dict['ub_string_dynamic_array_value'].basetype.maximum_size == '5' - - assert isinstance(string_slot_types_dict['string_dynamic_array_value'], UnboundedSequence) - assert isinstance(string_slot_types_dict['string_dynamic_array_value'].basetype, String) - assert string_slot_types_dict['string_dynamic_array_value'].basetype.maximum_size == 'None' - - assert isinstance(string_slot_types_dict['string_static_array_value'], Array) - assert isinstance(string_slot_types_dict['string_static_array_value'].basetype, String) - assert string_slot_types_dict['string_static_array_value'].size == 3 - assert string_slot_types_dict['string_static_array_value'].basetype.maximum_size == 'None' + assert isinstance(string_slot_types[0], Array) + assert isinstance(string_slot_types[0].basetype, String) + assert string_slot_types[0].size == 3 + assert string_slot_types[0].basetype.maximum_size == '5' + + assert isinstance(string_slot_types[1], BoundedSequence) + assert isinstance(string_slot_types[1].basetype, String) + assert string_slot_types[1].upper_bound == 10 + assert string_slot_types[1].basetype.maximum_size == '5' + + assert isinstance(string_slot_types[2], UnboundedSequence) + assert isinstance(string_slot_types[2].basetype, String) + assert string_slot_types[2].basetype.maximum_size == '5' + + assert isinstance(string_slot_types[3], UnboundedSequence) + assert isinstance(string_slot_types[3].basetype, String) + assert string_slot_types[3].basetype.maximum_size == 'None' + + assert isinstance(string_slot_types[4], Array) + assert isinstance(string_slot_types[4].basetype, String) + assert string_slot_types[4].size == 3 + assert string_slot_types[4].basetype.maximum_size == 'None'