Skip to content

Commit

Permalink
update tests and remove coverage for dict to avoid circular dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Mikael Arguedas <[email protected]>
  • Loading branch information
mikaelarguedas committed Mar 28, 2019
1 parent 4bc65c0 commit 0271e56
Showing 1 changed file with 38 additions and 71 deletions.
109 changes: 38 additions & 71 deletions rosidl_generator_py/test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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'

0 comments on commit 0271e56

Please sign in to comment.