def test_char_msg(): msg = Char() msg.data = 105 parsed_msg = json_to_msg(msg_to_json(msg), Char()) assert parsed_msg.data == msg.data
def test_string_msg(): msg = String() msg.data = 'Hello World!' parsed_msg = json_to_msg(msg_to_json(msg), String()) assert parsed_msg.data == msg.data
def test_bool_msg(): msg = Bool() msg.data = True parsed_msg = json_to_msg(msg_to_json(msg), Bool()) assert parsed_msg.data == msg.data
def test_byte_msg(): msg = Byte() msg.data = b'\x10' parsed_msg = json_to_msg(msg_to_json(msg), Byte()) assert parsed_msg.data == msg.data
def test_floats_msg_negative(): msg = Floats() msg.float32 = -3.1415 msg.float64 = -3.14159265359 parsed_msg = json_to_msg(msg_to_json(msg), Floats()) assert parsed_msg.float32 == msg.float32 assert parsed_msg.float64 == msg.float64
def test_unsigned_integers_msg(): msg = UnsignedIntegers() msg.uint8 = 200 msg.uint16 = 20000 msg.uint32 = 2000000000 msg.uint64 = 2000000000000 parsed_msg = json_to_msg(msg_to_json(msg), UnsignedIntegers()) assert parsed_msg.uint8 == msg.uint8 assert parsed_msg.uint16 == msg.uint16 assert parsed_msg.uint32 == msg.uint32 assert parsed_msg.uint64 == msg.uint64
def test_integers_msg_negative(): msg = Integers() msg.int8 = -100 msg.int16 = -10000 msg.int32 = -1000000000 msg.int64 = -1000000000000 parsed_msg = json_to_msg(msg_to_json(msg), Integers()) assert parsed_msg.int8 == msg.int8 assert parsed_msg.int16 == msg.int16 assert parsed_msg.int32 == msg.int32 assert parsed_msg.int64 == msg.int64
def test_bounded_dynamic_array_msg(): msg = BoundedDynamicArrays() msg.int8_bounded_dynamic_array = [1, 2, 3] msg.uint8_bounded_dynamic_array = [1, 2, 3] msg.float32_bounded_dynamic_array = [-3.1415, 3.1415] msg.bool_bounded_dynamic_array = [True, False, True] msg.string_bounded_dynamic_array = ["hello", "world", "!"] parsed_msg = json_to_msg(msg_to_json(msg), BoundedDynamicArrays()) assert parsed_msg.int8_bounded_dynamic_array == msg.int8_bounded_dynamic_array assert parsed_msg.uint8_bounded_dynamic_array == msg.uint8_bounded_dynamic_array assert parsed_msg.float32_bounded_dynamic_array == msg.float32_bounded_dynamic_array assert parsed_msg.bool_bounded_dynamic_array == msg.bool_bounded_dynamic_array assert parsed_msg.string_bounded_dynamic_array == msg.string_bounded_dynamic_array
def test_non_floats_msg(): msg = NonFloats() msg.integers.int8 = 100 msg.integers.int16 = -10000 msg.integers.int32 = 1000000000 msg.integers.int64 = -1000000000000 msg.unsigned_integers.uint8 = 200 msg.unsigned_integers.uint16 = 20000 msg.unsigned_integers.uint32 = 2000000000 msg.unsigned_integers.uint64 = 2000000000000 parsed_msg = json_to_msg(msg_to_json(msg), NonFloats()) assert parsed_msg.integers.int8 == msg.integers.int8 assert parsed_msg.integers.int16 == msg.integers.int16 assert parsed_msg.integers.int32 == msg.integers.int32 assert parsed_msg.integers.int64 == msg.integers.int64 assert parsed_msg.unsigned_integers.uint8 == msg.unsigned_integers.uint8 assert parsed_msg.unsigned_integers.uint16 == msg.unsigned_integers.uint16 assert parsed_msg.unsigned_integers.uint32 == msg.unsigned_integers.uint32 assert parsed_msg.unsigned_integers.uint64 == msg.unsigned_integers.uint64
def test_array_msg(): msg = Arrays() msg.int8_array = [1, 2, 3] msg.uint8_array = [1, 2, 3] msg.float32_array = [-3.1415, 3.1415] msg.bool_array = [True, False, True] msg.string_array = ["hello", "world", "!"] msg.byte_array = [b'\x01', b'\x10', b'\x11'] non_floats_msg = NonFloats() non_floats_msg.integers.int8 = 100 non_floats_msg.integers.int16 = -10000 non_floats_msg.integers.int32 = 1000000000 non_floats_msg.integers.int64 = -1000000000000 non_floats_msg.unsigned_integers.uint8 = 200 non_floats_msg.unsigned_integers.uint16 = 20000 non_floats_msg.unsigned_integers.uint32 = 2000000000 non_floats_msg.unsigned_integers.uint64 = 2000000000000 msg.non_floats_array = [non_floats_msg, non_floats_msg] non_numbers_msg = NonNumbers() non_numbers_msg.boolean = True non_numbers_msg.string = "hello" non_numbers_msg.byte = b'\x01' msg.non_numbers_array = [non_numbers_msg, non_numbers_msg] parsed_msg = json_to_msg(msg_to_json(msg), Arrays()) assert parsed_msg.int8_array == msg.int8_array assert parsed_msg.uint8_array == msg.uint8_array assert parsed_msg.float32_array == msg.float32_array assert parsed_msg.bool_array == msg.bool_array assert parsed_msg.string_array == msg.string_array assert parsed_msg.byte_array == msg.byte_array assert parsed_msg.non_floats_array == msg.non_floats_array assert parsed_msg.non_numbers_array == msg.non_numbers_array
def test_numbers_msg(): msg = Numbers() msg.floats.float32 = 3.1415 msg.floats.float64 = -3.14159265359 msg.non_floats.integers.int8 = 100 msg.non_floats.integers.int16 = -10000 msg.non_floats.integers.int32 = 1000000000 msg.non_floats.integers.int64 = -1000000000000 msg.non_floats.unsigned_integers.uint8 = 200 msg.non_floats.unsigned_integers.uint16 = 20000 msg.non_floats.unsigned_integers.uint32 = 2000000000 msg.non_floats.unsigned_integers.uint64 = 2000000000000 parsed_msg = json_to_msg(msg_to_json(msg), Numbers()) parsed_floats = parsed_msg.floats floats = msg.floats assert parsed_floats.float32 == floats.float32 assert parsed_floats.float64 == floats.float64 parsed_integers = parsed_msg.non_floats.integers integers = msg.non_floats.integers assert parsed_integers.int8 == integers.int8 assert parsed_integers.int16 == integers.int16 assert parsed_integers.int32 == integers.int32 assert parsed_integers.int64 == integers.int64 parsed_unsigned_integers = parsed_msg.non_floats.unsigned_integers unsigned_integers = msg.non_floats.unsigned_integers assert parsed_unsigned_integers.uint8 == unsigned_integers.uint8 assert parsed_unsigned_integers.uint16 == unsigned_integers.uint16 assert parsed_unsigned_integers.uint32 == unsigned_integers.uint32 assert parsed_unsigned_integers.uint64 == unsigned_integers.uint64