mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 18:04:20 +08:00
Fix protocol regressions and clarify experimental APIs
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
"""针对本轮 A 股增强功能的单元测试。"""
|
||||
|
||||
import pytest
|
||||
import struct
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
from xmtdx import TdxClient, Market
|
||||
from unittest.mock import patch
|
||||
|
||||
from xmtdx import Market, TdxClient
|
||||
from xmtdx.models.quote import SecurityQuote
|
||||
from xmtdx.models.security import SecurityInfo
|
||||
from xmtdx.models.timeseries import TransactionRecord
|
||||
from xmtdx.models.quote import SecurityQuote
|
||||
from xmtdx.models.stats import FundFlow, HistoricalFundFlow, MarketStat
|
||||
|
||||
|
||||
@patch("xmtdx.client.TdxConnection")
|
||||
def test_get_fund_flow_logic(mock_conn_cls):
|
||||
def test_get_fund_flow_logic(_mock_conn_cls):
|
||||
"""测试资金流分类计算逻辑。"""
|
||||
mock_conn = mock_conn_cls.return_value
|
||||
client = TdxClient("127.0.0.1")
|
||||
|
||||
# 构造模拟 Tick 数据
|
||||
@@ -31,7 +30,7 @@ def test_get_fund_flow_logic(mock_conn_cls):
|
||||
assert flow.main_net_inflow == 1000000.0 - 250000.0
|
||||
|
||||
@patch("xmtdx.client.TdxConnection")
|
||||
def test_get_security_list_all_filtering(mock_conn_cls):
|
||||
def test_get_security_list_all_filtering(_mock_conn_cls):
|
||||
"""测试三市 A 股过滤与行业挂载逻辑。"""
|
||||
client = TdxClient("127.0.0.1")
|
||||
|
||||
@@ -56,18 +55,18 @@ def test_get_security_list_all_filtering(mock_conn_cls):
|
||||
patch.object(TdxClient, "get_security_list", side_effect=mock_get_list):
|
||||
|
||||
all_stocks = client.get_security_list_all()
|
||||
|
||||
assert len(all_stocks) == 3
|
||||
|
||||
# 预期只有 SH 和 SZ,BJ 已在扫描中降级移除
|
||||
assert len(all_stocks) == 2
|
||||
codes = [s.code for s in all_stocks]
|
||||
assert "600000" in codes
|
||||
assert "000001" in codes
|
||||
assert "830000" in codes
|
||||
|
||||
assert "830000" not in codes
|
||||
s0 = next(s for s in all_stocks if s.code == "600000")
|
||||
assert s0.industry_tdx == "T01"
|
||||
|
||||
@patch("xmtdx.client.TdxConnection")
|
||||
def test_get_market_stat_mapping(mock_conn_cls):
|
||||
def test_get_market_stat_mapping(_mock_conn_cls):
|
||||
"""测试市场统计字段映射。"""
|
||||
client = TdxClient("127.0.0.1")
|
||||
|
||||
@@ -75,18 +74,23 @@ def test_get_market_stat_mapping(mock_conn_cls):
|
||||
Market.SH, "880005",
|
||||
price=3000.0, # up
|
||||
pre_close=2000.0, # down
|
||||
open=500.0, # neutral
|
||||
open=0,
|
||||
high=5500.0, # total
|
||||
low=100.0, vol=1000000.0, cur_vol=0, amount=50000000.0,
|
||||
low=500.0, # neutral (low=500 -> neutral_count=500)
|
||||
vol=1000000.0, cur_vol=0, amount=50000000.0,
|
||||
s_vol=0, b_vol=0, active1=0, active2=0,
|
||||
bid1=0, bid_vol1=0, bid2=0, bid_vol2=0, bid3=0, bid_vol3=0, bid4=0, bid_vol4=0, bid5=0, bid_vol5=0,
|
||||
ask1=0, ask_vol1=0, ask2=0, ask_vol2=0, ask3=0, ask_vol3=0, ask4=0, ask_vol4=0, ask5=0, ask_vol5=0,
|
||||
bid1=0, bid_vol1=0, bid2=0, bid_vol2=0, bid3=0, bid_vol3=0,
|
||||
bid4=0, bid_vol4=0, bid5=0, bid_vol5=0,
|
||||
ask1=0, ask_vol1=0, ask2=0, ask_vol2=0, ask3=0, ask_vol3=0,
|
||||
ask4=0, ask_vol4=0, ask5=0, ask_vol5=0,
|
||||
rise_speed=0, limit_up=0, limit_down=0
|
||||
)
|
||||
|
||||
with patch.object(TdxClient, "get_security_quotes", return_value=[mock_quote]):
|
||||
stat = client.get_market_stat()
|
||||
assert stat.up_count == 3000
|
||||
assert stat.down_count == 2000
|
||||
assert stat.neutral_count == 500
|
||||
assert stat.total_count == 5500
|
||||
|
||||
def test_get_history_fund_flow_parsing():
|
||||
|
||||
Reference in New Issue
Block a user