Files
pyquantdata/tests/test_classify.py
T
openbot d37c697bbe M1 最小闭环:CLI + FastAPI 网关 + SQL 闸 + 100% 覆盖率验收链
- CLI:init/serve/update/query/export/status(typer + rich),单写者锁三元判活
- 存储:DuckDB schema migrations(14 表 + 8 联邦视图,语句元组逐条执行)
- ETL:A股证券/日历/日K,整区替换幂等;日历全年补全(calendar 语义唯一)
- 网关:POST /v1/query(线程池 + interrupt 超时 504)、/v1/export、meta/stats/state、healthz/ready
- 安全:SQL 闸 sqlglot fail-closed(文件/网络表函数默认拒)、非 loopback 空 token 拒启、导出路径双判
- 验收:254 测试全绿、1265 语句 100% 覆盖、[CI] 真起服验收链、smoke_m1.py 交付自检
- 文档:设计文档 v0.7(圆桌 45 条采纳 + 3 条实施校准),README 重写
- 发布:release.yml Trusted Publishing(OIDC 免密钥),action refs 已核验
2026-09-24 09:06:47 +08:00

48 lines
1.3 KiB
Python

"""A股分类纯函数。"""
from __future__ import annotations
import pytest
from pyquantdata.sources.classify import classify_cn, exchange_of
@pytest.mark.parametrize(
"symbol,category",
[
("sh600000", "stock"),
("sh600519", "stock"),
("sh688001", "stock"), # 科创板
("sz000001", "stock"),
("sz300750", "stock"), # 创业板
("bj430047", "stock"),
("bj833171", "stock"),
("sh000001", "index"), # 上证指数
("sz399001", "index"),
("sh510300", "etf"),
("sz159915", "etf"),
("sh513100", "etf"),
("sh508056", "reits"), # 特例优先于 etf 前缀 sh50
("sh510050", "etf"),
("sh110059", "cbond"),
("sz123456", "cbond"),
("sz127045", "cbond"),
("SH600000", "stock"), # 大小写归一
],
)
def test_classify_cn(symbol, category):
assert classify_cn(symbol) == category
@pytest.mark.parametrize("symbol", ["", "xx123", "sh999999", "hk00700"])
def test_classify_cn_unknown_is_other(symbol):
assert classify_cn(symbol) == "other"
@pytest.mark.parametrize(
"symbol,ex",
[("sh600000", "sh"), ("sz000001", "sz"), ("bj430047", "bj"), ("AAPL", "")],
)
def test_exchange_of(symbol, ex):
assert exchange_of(symbol) == ex