mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 15:44:18 +08:00
- Package directory: src/xmtdx/ -> src/easy_tdx/ - Import path: from easy_tdx import ... - pip install easy-tdx - Add LICENSE (MIT) with upstream attribution (pytdx, xmtdx) - Add NOTICE with detailed attribution - Update all examples, tests, scripts, docs - Bump version to 1.0.0 BREAKING CHANGE: import path changed from `xmtdx` to `easy_tdx` Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""响应帧头解析与解压单元测试。"""
|
|
|
|
import struct
|
|
import zlib
|
|
|
|
from easy_tdx.codec.frame import HEADER_SIZE, decompress_body, parse_header
|
|
|
|
|
|
def _make_header(zipsize: int, unzipsize: int) -> bytes:
|
|
return struct.pack("<IIIHH", 0, 0, 0, zipsize, unzipsize)
|
|
|
|
|
|
class TestParseHeader:
|
|
def test_uncompressed(self):
|
|
h = parse_header(_make_header(100, 100))
|
|
assert h.zipsize == 100
|
|
assert h.unzipsize == 100
|
|
|
|
def test_compressed(self):
|
|
h = parse_header(_make_header(50, 200))
|
|
assert h.zipsize == 50
|
|
assert h.unzipsize == 200
|
|
|
|
def test_header_size(self):
|
|
assert HEADER_SIZE == 16
|
|
|
|
|
|
class TestDecompressBody:
|
|
def test_no_compression(self):
|
|
h = parse_header(_make_header(5, 5))
|
|
body = b"hello"
|
|
assert decompress_body(h, body) == b"hello"
|
|
|
|
def test_zlib_decompression(self):
|
|
original = b"hello world" * 10
|
|
compressed = zlib.compress(original)
|
|
h = parse_header(_make_header(len(compressed), len(original)))
|
|
result = decompress_body(h, compressed)
|
|
assert result == original
|