mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 14:24:15 +08:00
test: 修复 PR #193 合并后的 12 个测试 (alerts 参数/None 语义/自包含插件)
This commit is contained in:
@@ -281,9 +281,10 @@ def test_ai_settings_keep_provider_models_separate(monkeypatch):
|
||||
# ── 输出上限 / 上下文窗口配置 ─────────────────────────────────
|
||||
|
||||
|
||||
def test_resolve_max_tokens_defaults_to_config_cap(monkeypatch):
|
||||
def test_resolve_max_tokens_none_stays_unlimited(monkeypatch):
|
||||
"""None = 不传上限(推理模型放开) — 不能被映射成配置上限, 见 main 语义。"""
|
||||
monkeypatch.setattr(ai_provider, "current_ai_max_output_tokens", lambda: 8192)
|
||||
assert ai_provider._resolve_max_tokens(None) == 8192
|
||||
assert ai_provider._resolve_max_tokens(None) is None
|
||||
|
||||
|
||||
def test_resolve_max_tokens_clamps_above_cap(monkeypatch):
|
||||
@@ -339,7 +340,8 @@ async def test_generate_ai_text_clamps_max_tokens_to_config_cap(monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_ai_text_defaults_to_config_cap(monkeypatch):
|
||||
async def test_generate_ai_text_default_cap_and_none_passthrough(monkeypatch):
|
||||
"""默认 3000 且被钳制; 显式 None 贯穿为不限制。"""
|
||||
captured: dict = {}
|
||||
monkeypatch.setattr(ai_provider, "is_codex_cli_provider", lambda: False)
|
||||
monkeypatch.setattr(ai_provider, "current_ai_max_output_tokens", lambda: 4000)
|
||||
@@ -351,7 +353,11 @@ async def test_generate_ai_text_defaults_to_config_cap(monkeypatch):
|
||||
|
||||
monkeypatch.setattr(ai_provider, "_run_openai_once", fake_run)
|
||||
await ai_provider.generate_ai_text([{"role": "user", "content": "hi"}])
|
||||
assert captured["max_tokens"] == 4000
|
||||
assert captured["max_tokens"] == 3000 # 默认值, 未超 cap 原样下发
|
||||
await ai_provider.generate_ai_text(
|
||||
[{"role": "user", "content": "hi"}], max_tokens=None,
|
||||
)
|
||||
assert captured["max_tokens"] is None # None = 推理模型放开, 不钳制
|
||||
|
||||
|
||||
def test_save_ai_settings_persists_token_sizes(monkeypatch):
|
||||
|
||||
@@ -31,8 +31,21 @@ def _patch_uv_install(monkeypatch, returncodes):
|
||||
return calls
|
||||
|
||||
|
||||
def test_install_plugin_uv_targets_running_interpreter(monkeypatch):
|
||||
def _fake_python_plugin(monkeypatch, tmp_path):
|
||||
"""在临时目录铺设最小 python 插件, 并把 plugins_dir 指过去 (自包含)。"""
|
||||
pdir = tmp_path / "baostock"
|
||||
pdir.mkdir()
|
||||
(pdir / "plugin.yaml").write_text(
|
||||
"name: baostock\nruntime: python\nentry: p:provider\n", encoding="utf-8",
|
||||
)
|
||||
(pdir / "requirements.txt").write_text("baostock\n", encoding="utf-8")
|
||||
monkeypatch.setattr(loader, "plugins_dir", lambda: tmp_path)
|
||||
return pdir
|
||||
|
||||
|
||||
def test_install_plugin_uv_targets_running_interpreter(monkeypatch, tmp_path):
|
||||
"""uv 分支必须传 --python sys.executable, 不能留给 uv 自动探测。"""
|
||||
_fake_python_plugin(monkeypatch, tmp_path)
|
||||
calls = _patch_uv_install(monkeypatch, [0])
|
||||
|
||||
ok, msg = loader.install_plugin("baostock")
|
||||
@@ -45,8 +58,9 @@ def test_install_plugin_uv_targets_running_interpreter(monkeypatch):
|
||||
assert uv_cmd[idx + 1] == sys.executable
|
||||
|
||||
|
||||
def test_install_plugin_uv_retry_keeps_python_target(monkeypatch):
|
||||
def test_install_plugin_uv_retry_keeps_python_target(monkeypatch, tmp_path):
|
||||
"""exit 2 → --no-config 重试时也必须保持 --python 目标。"""
|
||||
_fake_python_plugin(monkeypatch, tmp_path)
|
||||
calls = _patch_uv_install(monkeypatch, [2, 0])
|
||||
|
||||
ok, msg = loader.install_plugin("baostock")
|
||||
@@ -58,7 +72,7 @@ def test_install_plugin_uv_retry_keeps_python_target(monkeypatch):
|
||||
assert cmd[idx + 1] == sys.executable
|
||||
|
||||
|
||||
def test_uninstall_plugin_uv_targets_running_interpreter(monkeypatch):
|
||||
def test_uninstall_plugin_uv_targets_running_interpreter(monkeypatch, tmp_path):
|
||||
"""uv 卸载同样必须传 --python sys.executable, 否则会动到基础解释器。"""
|
||||
calls: list[list[str]] = []
|
||||
|
||||
@@ -69,6 +83,7 @@ def test_uninstall_plugin_uv_targets_running_interpreter(monkeypatch):
|
||||
calls.append(list(cmd))
|
||||
return subprocess.CompletedProcess(cmd, 0)
|
||||
|
||||
_fake_python_plugin(monkeypatch, tmp_path)
|
||||
monkeypatch.setattr(loader.shutil, "which", fake_which)
|
||||
monkeypatch.setattr(loader.subprocess, "run", fake_run)
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ def _filter_history_strategy(
|
||||
trailing_take_profit_activate=None,
|
||||
trailing_take_profit_drawdown=None,
|
||||
max_hold_days=None,
|
||||
alerts=[],
|
||||
filter_fn=None,
|
||||
filter_history_fn=lambda df, params: df,
|
||||
lookback_days=lookback_days,
|
||||
|
||||
Reference in New Issue
Block a user