Files
ashare-data/tests/test_daily_source_codes.py
T
2026-05-17 15:51:10 +08:00

53 lines
1.4 KiB
Python

"""验证 daily.py 中各数据源的代码格式映射"""
from src.fetchers.daily import (
_code_to_sina,
_code_to_tencent,
_code_to_eastmoney,
)
# ── 新浪/腾讯:sh{code}/sz{code} ──
def test_sina_shanghai_main():
assert _code_to_sina("600000") == "sh600000"
def test_sina_shanghai_kechuang():
assert _code_to_sina("688981") == "sh688981"
def test_sina_shenzhen_chinext():
assert _code_to_sina("300750") == "sz300750"
assert _code_to_sina("000001") == "sz000001"
def test_sina_beijing_returns_none():
assert _code_to_sina("920001") is None
def test_tencent_same_as_sina():
# 腾讯走与新浪相同的前缀映射
assert _code_to_tencent("600000") == "sh600000"
assert _code_to_tencent("000001") == "sz000001"
assert _code_to_tencent("920001") is None
# ── 东方财富:1.{code} 沪市,0.{code} 深市 ──
def test_eastmoney_shanghai_uses_prefix_1():
assert _code_to_eastmoney("600000") == "1.600000"
assert _code_to_eastmoney("688981") == "1.688981"
# B 股 9 开头也走沪市
assert _code_to_eastmoney("900901") == "1.900901"
def test_eastmoney_shenzhen_uses_prefix_0():
assert _code_to_eastmoney("000001") == "0.000001"
assert _code_to_eastmoney("300750") == "0.300750"
assert _code_to_eastmoney("002594") == "0.002594"
def test_eastmoney_beijing_returns_none():
assert _code_to_eastmoney("920001") is None