log
2026-07-09 c4fc32d73b36eb42beed034a375a82ecc992da06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import importlib
import subprocess
import sys
import unittest
from pathlib import Path
from unittest.mock import patch
 
 
PROJECT_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(PROJECT_ROOT))
 
a_stock_manager = importlib.import_module("a_stock_manager")
 
 
class AStockManagerRunScriptTests(unittest.TestCase):
    def test_run_script_streams_child_output(self):
        completed = subprocess.CompletedProcess(
            args=[sys.executable, "fake.py"],
            returncode=0,
        )
 
        with patch.object(a_stock_manager.subprocess, "run", return_value=completed) as run:
            result = a_stock_manager.run_script("fake.py", "fake task")
 
        self.assertTrue(result)
        kwargs = run.call_args.kwargs
        self.assertIs(kwargs["cwd"], a_stock_manager.project_root)
        self.assertFalse(kwargs["capture_output"])
        self.assertNotIn("stdout", kwargs)
        self.assertNotIn("stderr", kwargs)
 
    def test_run_script_passes_extra_args(self):
        completed = subprocess.CompletedProcess(
            args=[sys.executable, "fake.py"],
            returncode=0,
        )
 
        with patch.object(a_stock_manager.subprocess, "run", return_value=completed) as run:
            result = a_stock_manager.run_script(
                "fake.py",
                "fake task",
                args=["--n-stocks", "all"],
            )
 
        self.assertTrue(result)
        self.assertEqual(
            run.call_args.args[0],
            [
                sys.executable,
                str(a_stock_manager.scripts_dir / "fake.py"),
                "--n-stocks",
                "all",
            ],
        )
 
    def test_prompt_stock_count_args_supports_all(self):
        with patch("builtins.input", return_value="2"):
            args, description = a_stock_manager.prompt_stock_count_args()
 
        self.assertEqual(args, ["--n-stocks", "all"])
        self.assertIn("全量", description)
 
 
if __name__ == "__main__":
    unittest.main()