Replace the V1 commands/services split with a flat, direct architecture: - cli.py dispatches directly to service functions - New services: account, market, trade, opportunity - Thin Binance wrappers: spot_client, um_futures_client - Add audit logging, runtime paths, and TOML config - Remove legacy V1 code: commands/, precheck, review engine, smart executor - Add ruff + mypy toolchain and fix edge cases in trade params Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
"""CLI tests for CoinHunter V2."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from coinhunter import cli
|
|
|
|
|
|
class CLITestCase(unittest.TestCase):
|
|
def test_help_includes_v2_commands(self):
|
|
parser = cli.build_parser()
|
|
help_text = parser.format_help()
|
|
self.assertIn("init", help_text)
|
|
self.assertIn("account", help_text)
|
|
self.assertIn("opportunity", help_text)
|
|
|
|
def test_init_dispatches(self):
|
|
captured = {}
|
|
with patch.object(cli, "ensure_init_files", return_value={"force": True, "root": "/tmp/ch"}), patch.object(
|
|
cli, "print_json", side_effect=lambda payload: captured.setdefault("payload", payload)
|
|
):
|
|
result = cli.main(["init", "--force"])
|
|
self.assertEqual(result, 0)
|
|
self.assertTrue(captured["payload"]["force"])
|
|
|
|
def test_old_command_is_rejected(self):
|
|
with self.assertRaises(SystemExit):
|
|
cli.main(["exec", "bal"])
|
|
|
|
def test_runtime_error_is_rendered_cleanly(self):
|
|
stderr = io.StringIO()
|
|
with patch.object(cli, "load_config", side_effect=RuntimeError("boom")), patch("sys.stderr", stderr):
|
|
result = cli.main(["market", "tickers", "BTCUSDT"])
|
|
self.assertEqual(result, 1)
|
|
self.assertIn("error: boom", stderr.getvalue())
|