def test_set_message_fields_invalid(): msg = message_fixtures.get_msg_basic_types()[0] invalid_field = {} invalid_field['test_invalid_field'] = 42 with pytest.raises(AttributeError): set_message_fields(msg, invalid_field) invalid_type = {} invalid_type['int32_value'] = 'this is not an integer' with pytest.raises(ValueError): set_message_fields(msg, invalid_type) msg = message_fixtures.get_msg_nested()[0] with pytest.raises(TypeError): set_message_fields(msg, 'not_a_dict')
def test_set_message_fields_nested_type(): msg_basic_types = message_fixtures.get_msg_basic_types()[0] msg0 = message_fixtures.get_msg_nested()[0] msg0.basic_types_value.bool_value = False msg0.basic_types_value.char_value = 3 msg0.basic_types_value.int32_value = 42 assert msg0.basic_types_value != msg_basic_types test_values = {} test_values['basic_types_value'] = msg_basic_types set_message_fields(msg0, test_values) assert msg0.basic_types_value == msg_basic_types
def test_set_message_fields_none(): # Smoke-test on a bunch of messages msgs = [] msgs.extend(message_fixtures.get_msg_arrays()) msgs.extend(message_fixtures.get_msg_basic_types()) msgs.extend(message_fixtures.get_msg_bounded_sequences()) msgs.extend(message_fixtures.get_msg_builtins()) msgs.extend(message_fixtures.get_msg_constants()) msgs.extend(message_fixtures.get_msg_defaults()) msgs.extend(message_fixtures.get_msg_empty()) msgs.extend(message_fixtures.get_msg_multi_nested()) msgs.extend(message_fixtures.get_msg_nested()) msgs.extend(message_fixtures.get_msg_strings()) msgs.extend(message_fixtures.get_msg_unbounded_sequences()) for m in msgs: original_m = copy.copy(m) set_message_fields(m, {}) # Assert message is not modified when setting no fields assert original_m == m
def test_primitives(): # Smoke-test the formatters on a bunch of messages msgs = [] msgs.extend(message_fixtures.get_msg_arrays()) msgs.extend(message_fixtures.get_msg_basic_types()) msgs.extend(message_fixtures.get_msg_bounded_sequences()) msgs.extend(message_fixtures.get_msg_builtins()) msgs.extend(message_fixtures.get_msg_constants()) msgs.extend(message_fixtures.get_msg_defaults()) msgs.extend(message_fixtures.get_msg_empty()) msgs.extend(message_fixtures.get_msg_multi_nested()) msgs.extend(message_fixtures.get_msg_nested()) msgs.extend(message_fixtures.get_msg_strings()) msgs.extend(message_fixtures.get_msg_unbounded_sequences()) for m in msgs: message_to_csv(m, 100) message_to_csv(m, None) message_to_ordereddict(m, 100) message_to_ordereddict(m, None) message_to_yaml(m, 100) message_to_yaml(m, None)
def test_primitives(): register_yaml_representer() # Smoke-test the formatters on a bunch of messages msgs = [] msgs.extend(message_fixtures.get_msg_bounded_array_nested()) msgs.extend(message_fixtures.get_msg_bounded_array_primitives()) msgs.extend(message_fixtures.get_msg_builtins()) msgs.extend(message_fixtures.get_msg_dynamic_array_nested()) msgs.extend(message_fixtures.get_msg_dynamic_array_primitives()) msgs.extend(message_fixtures.get_msg_dynamic_array_primitives_nested()) msgs.extend(message_fixtures.get_msg_empty()) msgs.extend(message_fixtures.get_msg_nested()) msgs.extend(message_fixtures.get_msg_primitives()) msgs.extend(message_fixtures.get_msg_static_array_nested()) msgs.extend(message_fixtures.get_msg_static_array_primitives()) args = Namespace() args.full_length = False args.truncate_length = DEFAULT_TRUNCATE_LENGTH for m in msgs: msg_to_yaml(args, m) msg_to_csv(args, m)