mirror of
https://github.com/AkitaEngineering/Akita-Meshtastic-Meshcore-Bridge.git
synced 2026-03-28 17:42:42 +01:00
20 lines
628 B
Python
20 lines
628 B
Python
import pytest
|
|
import json
|
|
from ammb.protocol import get_serial_protocol_handler, JsonNewlineProtocol
|
|
|
|
def test_json_newline_encode():
|
|
handler = JsonNewlineProtocol()
|
|
data = {"key": "value"}
|
|
encoded = handler.encode(data)
|
|
assert encoded == b'{"key": "value"}\n'
|
|
|
|
def test_factory_function():
|
|
handler = get_serial_protocol_handler('json_newline')
|
|
assert isinstance(handler, JsonNewlineProtocol)
|
|
|
|
def test_raw_serial_handler():
|
|
handler = get_serial_protocol_handler('raw_serial')
|
|
raw_data = b'\x01\x02\x03'
|
|
decoded = handler.decode(raw_data)
|
|
assert decoded['payload'] == "MC_BIN: 010203
|