|
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | # -------------------------------------------------------------------------------------------- |
5 | 5 |
|
6 | | -import sys |
7 | 6 | import types |
8 | 7 | import unittest |
9 | 8 | from unittest.mock import patch, MagicMock |
|
22 | 21 | ERROR_COLOR=MagicMock(), |
23 | 22 | HELP_COLOR=MagicMock(), |
24 | 23 | ), |
25 | | - console=mock_console_mod, # 添加 console 子模块 |
| 24 | + console=mock_console_mod, |
26 | 25 | ) |
27 | 26 | ) |
28 | 27 |
|
|
32 | 31 | ) |
33 | 32 | ) |
34 | 33 |
|
35 | | -# 注册所有可能被 import 的路径 |
36 | | -sys.modules.update({ |
37 | | - 'holmes': mock_holmes, |
38 | | - 'holmes.interactive': mock_holmes.interactive, |
39 | | - 'holmes.utils': mock_holmes.utils, |
40 | | - 'holmes.utils.colors': mock_holmes.utils.colors, |
41 | | - 'holmes.utils.console': mock_holmes.utils.console, |
42 | | - 'holmes.utils.console.logging': mock_holmes.utils.console.logging, |
43 | | - 'rich': mock_rich, |
44 | | - 'rich.console': mock_rich.console, |
45 | | -}) |
46 | | - |
47 | 34 |
|
48 | 35 | class TestAksAgentInit(unittest.TestCase): |
49 | 36 |
|
| 37 | + def setUp(self): |
| 38 | + patcher = patch.dict( |
| 39 | + 'sys.modules', |
| 40 | + { |
| 41 | + 'holmes': mock_holmes, |
| 42 | + 'holmes.interactive': mock_holmes.interactive, |
| 43 | + 'holmes.utils': mock_holmes.utils, |
| 44 | + 'holmes.utils.colors': mock_holmes.utils.colors, |
| 45 | + 'holmes.utils.console': mock_holmes.utils.console, |
| 46 | + 'holmes.utils.console.logging': mock_holmes.utils.console.logging, |
| 47 | + 'rich': mock_rich, |
| 48 | + 'rich.console': mock_rich.console, |
| 49 | + } |
| 50 | + ) |
| 51 | + self.addCleanup(patcher.stop) |
| 52 | + patcher.start() |
| 53 | + |
50 | 54 | @patch('holmes.interactive.SlashCommands') |
51 | 55 | @patch('holmes.utils.colors.ERROR_COLOR') |
52 | 56 | @patch('holmes.utils.colors.HELP_COLOR') |
|
0 commit comments