Tortoise/tests/test_tencent.py
2026-06-23 10:37:31 +08:00

50 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""腾讯财经适配器测试。"""
from sidecar.sources.tencent import parse_tencent_payload, snapshot_from_tencent_fields
def test_1_1_tencent_snapshot_uses_correct_pb_index() -> None:
"""
功能说明:验证腾讯财经快照字段映射。
参数说明:无。
返回值说明:无返回值。
注意事项:用例编号 1-1重点确认索引 46 才是 PB索引 43 不是 PB。
"""
fields = [""] * 88
fields[1] = "浦发银行"
fields[3] = "10.50"
fields[4] = "10.00"
fields[30] = "20260623150102"
fields[31] = "0.50"
fields[32] = "5.00"
fields[39] = "6.70"
fields[43] = "2.22"
fields[44] = "1000"
fields[45] = "800"
fields[46] = "0.66"
fields[47] = "11.00"
fields[48] = "9.00"
fields[52] = "7.80"
snapshot = snapshot_from_tencent_fields("sh600000", fields)
assert snapshot.name == "浦发银行"
assert snapshot.pe_ttm == 6.70
assert snapshot.pb == 0.66
assert snapshot.pe_static == 7.80
def test_1_2_parse_tencent_payload() -> None:
"""
功能说明:验证腾讯财经原始响应解析。
参数说明:无。
返回值说明:无返回值。
注意事项:用例编号 1-2响应至少包含 53 个字段。
"""
fields = ["v"] * 88
payload = 'v_sh600000="' + "~".join(fields) + '";'
parsed = parse_tencent_payload(payload)
assert len(parsed) == 88
assert parsed[0] == "v"