test+fix: 新浪 jsonp 稳健解析(容忍注释/括号包裹/尾部杂字符);Job API 测试改 tmp 种子库
- 真实响应含 /*...*/ 注释与 var data=([...]); 前缀 → _extract_jsonp 取首 '[' 至末 ']' - 新浪真实网络冒烟通过:财务 100 期(含披露日)+ 日K 最近窗口(source=sina/adjust=qfq) - TestJobsApi / experiments 用例改为 monkeypatch SessionLocal → tmp 种子库(5 股×300 日), 与真实全市场库(779 万行)解耦,全量稳定 <1min - pytest 全量 141 passed / ruff clean
This commit is contained in:
@@ -154,3 +154,18 @@ class TestFormatParity:
|
||||
# 与 Tushare 同 schema:必备字段齐全
|
||||
assert bar.symbol == "600519.SH"
|
||||
assert bar.close is not None
|
||||
|
||||
|
||||
class TestJsonpParens:
|
||||
def test_real_world_paren_wrapped(self) -> None:
|
||||
payload = 'var data=([{"day":"2024-08-30","close":"1710.0"}])'
|
||||
rows = _extract_jsonp(payload)
|
||||
assert rows[0]["close"] == "1710.0"
|
||||
|
||||
def test_with_leading_comment_and_trailing_semicolon(self) -> None:
|
||||
payload = (
|
||||
"/*<script>location.href='//sina.com';</script>*/\n"
|
||||
'var data=([{"day":"2024-08-30","close":"1710.0"}]);'
|
||||
)
|
||||
rows = _extract_jsonp(payload)
|
||||
assert rows[0]["close"] == "1710.0"
|
||||
|
||||
Reference in New Issue
Block a user