ksjsb/tests/test_dfp_sq0.py
2026-07-30 20:25:56 +08:00

32 lines
1.0 KiB
Python

import unittest
from core.dfp_sq0 import decode_sq0_string_fields, encode_sq0_device_info
class DfpSq0Tests(unittest.TestCase):
def test_lite_encoding_preserves_known_tag_order(self):
raw = encode_sq0_device_info({"k5": "a", "k14": "bc", "k113": "z"}, mode="lite")
self.assertEqual(raw.hex(), "2a0161720262638a07017a")
fields = decode_sq0_string_fields(raw)
self.assertEqual(
[(field["proto_tag"], field["value"]) for field in fields],
[(5, "a"), (14, "bc"), (113, "z")],
)
def test_empty_values_are_not_encoded(self):
raw = encode_sq0_device_info({"k5": "a", "k14": "", "k113": "z"}, mode="lite")
fields = decode_sq0_string_fields(raw)
self.assertEqual(
[(field["proto_tag"], field["value"]) for field in fields],
[(5, "a"), (113, "z")],
)
def test_unknown_key_is_rejected(self):
with self.assertRaises(KeyError):
encode_sq0_device_info({"k999": "x"}, mode="lite")
if __name__ == "__main__":
unittest.main()