stock/tests/unit/test_cli.py
ZhangPeng 9aecdd036c Initial commit: OpenClaw Trading - AI多智能体量化交易系统
- 添加项目核心代码和配置
- 添加前端界面 (Next.js)
- 添加单元测试
- 更新 .gitignore 排除缓存和依赖
2026-02-27 03:47:40 +08:00

38 lines
1.3 KiB
Python

"""Unit tests for OpenClaw CLI."""
import tempfile
from pathlib import Path
from typer.testing import CliRunner
from openclaw.cli.main import app
runner = CliRunner()
class TestCLI:
def test_init_creates_config(self):
with tempfile.TemporaryDirectory() as tmpdir:
config_path = Path(tmpdir) / "test_config.yaml"
result = runner.invoke(app, ["init", "--path", str(config_path)])
assert result.exit_code == 0
assert config_path.exists()
def test_init_fails_on_existing_config(self):
with tempfile.TemporaryDirectory() as tmpdir:
config_path = Path(tmpdir) / "test_config.yaml"
runner.invoke(app, ["init", "--path", str(config_path)])
result = runner.invoke(app, ["init", "--path", str(config_path)])
assert result.exit_code == 1
def test_run(self):
result = runner.invoke(app, ["run", "--mode", "simulation"])
assert result.exit_code == 0
def test_status(self):
result = runner.invoke(app, ["status"])
assert result.exit_code == 0
assert "trader-001" in result.output
def test_config_show(self):
result = runner.invoke(app, ["config", "show"])
# May fail without config, but command should exist
assert result.exit_code in [0, 1]