Skip to content

Commit

Permalink
restore original test, add test for SLOT_TYPES
Browse files Browse the repository at this point in the history
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
  • Loading branch information
mikaelarguedas committed May 2, 2019
1 parent d6589fd commit 64003b6
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion rosidl_generator_py/test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,63 @@ def test_out_of_range():


def test_slot_attributes():
a = Nested()
assert hasattr(a, 'get_fields_and_field_types')
assert hasattr(a, '__slots__')
nested_slot_types_dict = getattr(a, 'get_fields_and_field_types')()
nested_slots = getattr(a, '__slots__')
assert len(nested_slot_types_dict) == len(nested_slots)
expected_nested_slot_types_dict = {
'primitives': 'rosidl_generator_py/Primitives',
'two_primitives': 'rosidl_generator_py/Primitives[2]',
'up_to_three_primitives': 'sequence<rosidl_generator_py/Primitives, 3>',
'unbounded_primitives': 'sequence<rosidl_generator_py/Primitives>',
}
assert len(nested_slot_types_dict) == len(expected_nested_slot_types_dict)

for expected_field, expected_slot_type in expected_nested_slot_types_dict.items():
assert expected_field in nested_slot_types_dict.keys()
assert expected_slot_type == nested_slot_types_dict[expected_field]


def test_string_slot_attributes():
b = StringArrays()
assert hasattr(b, 'get_fields_and_field_types')
assert hasattr(b, '__slots__')
string_slot_types_dict = getattr(b, 'get_fields_and_field_types')()
string_slots = getattr(b, '__slots__')
assert len(string_slot_types_dict) == len(string_slots)
expected_string_slot_types_dict = {
'ub_string_static_array_value': 'string<5>[3]',
'ub_string_ub_array_value': 'sequence<string<5>, 10>',
'ub_string_dynamic_array_value': 'sequence<string<5>>',
'string_dynamic_array_value': 'sequence<string>',
'string_static_array_value': 'string[3]',
'string_bounded_array_value': 'sequence<string, 10>',
'def_string_dynamic_array_value': 'sequence<string>',
'def_string_static_array_value': 'string[3]',
'def_string_bounded_array_value': 'sequence<string, 10>',
'def_various_quotes': 'sequence<string>',
'def_various_commas': 'sequence<string>',
}

assert len(string_slot_types_dict) == len(expected_string_slot_types_dict)

for expected_field, expected_slot_type in expected_string_slot_types_dict.items():
assert expected_field in string_slot_types_dict.keys()
assert expected_slot_type == string_slot_types_dict[expected_field]


def test_modifying_slot_fields_and_types():
b = StringArrays()
assert hasattr(b, 'get_fields_and_field_types')
string_slot_types_dict = getattr(b, 'get_fields_and_field_types')()
string_slot_types_dict_len = len(string_slot_types_dict)
string_slot_types_dict[1] = 2
assert len(getattr(b, 'get_fields_and_field_types')()) == string_slot_types_dict_len


def test_slot_types():
a = Nested()
assert hasattr(a, 'SLOT_TYPES')
assert hasattr(a, '__slots__')
Expand Down Expand Up @@ -332,7 +389,7 @@ def test_slot_attributes():
assert nested_slot_types[3].value_type.name == 'Primitives'


def test_string_slot_attributes():
def test_string_slot_types():
b = StringArrays()
assert hasattr(b, 'SLOT_TYPES')
assert hasattr(b, '__slots__')
Expand Down

0 comments on commit 64003b6

Please sign in to comment.