Skip to content

Commit 8bc2368

Browse files
authored
test: enhance test coverage configuration and add comprehensive merge… (#27)
* test: enhance test coverage configuration and add comprehensive merge utility tests Updated coverage configuration to enforce 95% branch and line coverage requirements across all modules, moved exclusion patterns to pyproject.toml, and added extensive test cases for merge utility functions including tuple, set, frozenset, and object merging with no_new_field parameter. 将覆盖率配置更新为在所有模块中强制执行 95% 的分支和行覆盖率要求,将排除模式移至 pyproject.toml,并为合并实用程序函数添加了广泛的测试用例,包括 tuple、set、frozenset 和对象合并以及 no_new_field 参数。 Change-Id: Id9ac7a7a5a23a5a36f6148b268d1c3822fc7764a Signed-off-by: OhYee <[email protected]> * ci: consolidate test steps and update python version Consolidate test steps in CI workflow from separate unit tests and coverage steps into a single test with coverage step. Update python version from 0.0.9 to 3.10 in mypy configuration and exclude package init file from coverage reporting. Fix typo in test file for credential model. fixes typo in credential test parameter name ci: 合并测试步骤并更新python版本 在CI工作流程中将独立的单元测试和覆盖率步骤合并为单个带覆盖率的测试步骤。 在mypy配置中将python版本从0.0.9更新为3.10,并从覆盖率报告中排除包初始化文件。 修复测试文件中凭证模型的拼写错误。 修复凭证测试参数名称中的拼写错误 Change-Id: Icc362fb12d7cb67151bde40f391e631b0c9f9567 Signed-off-by: OhYee <[email protected]> --------- Signed-off-by: OhYee <[email protected]>
1 parent 16b54b1 commit 8bc2368

37 files changed

+13482
-103
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ jobs:
3030
run: |
3131
make mypy-check
3232
33-
- name: Run unit tests
34-
run: |
35-
make test-unit
36-
37-
- name: Run coverage
33+
- name: Run tests with coverage
3834
run: |
3935
make coverage
4036

agentrun/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ def __getattr__(name: str):
315315
for package_name in package_names:
316316
if package_name in error_str:
317317
raise ImportError(
318-
f"'{name}' requires the 'server' optional dependencies. "
319-
f"Install with: pip install {install_cmd}\n"
320-
f"Original error: {e}"
318+
f"'{name}' requires the 'server' optional"
319+
" dependencies. Install with: pip install"
320+
f" {install_cmd}\nOriginal error: {e}"
321321
) from e
322322
# 其他导入错误继续抛出
323323
raise

agentrun/model/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ProxyConfigEndpoint(BaseModel):
114114
base_url: Optional[str] = None
115115
model_names: Optional[List[str]] = None
116116
model_service_name: Optional[str] = None
117-
weight: Optional[str] = None
117+
weight: Optional[int] = None
118118

119119

120120
class ProxyConfigFallback(BaseModel):

coverage.yaml

Lines changed: 17 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,37 @@
1-
# 覆盖率配置文件
2-
# Coverage Configuration File
1+
# 覆盖率阈值配置文件
2+
# Coverage Threshold Configuration File
3+
#
4+
# 注意:文件排除配置已迁移到 pyproject.toml 的 [tool.coverage.*] 部分
5+
# Note: File exclusion settings have been moved to [tool.coverage.*] in pyproject.toml
36

47
# ============================================================================
58
# 全量代码覆盖率要求
69
# ============================================================================
710
full:
811
# 分支覆盖率要求 (百分比)
9-
branch_coverage: 0
12+
branch_coverage: 95
1013
# 行覆盖率要求 (百分比)
11-
line_coverage: 0
14+
line_coverage: 95
1215

1316
# ============================================================================
1417
# 增量代码覆盖率要求 (相对于基准分支的变更代码)
1518
# ============================================================================
1619
incremental:
1720
# 分支覆盖率要求 (百分比)
18-
branch_coverage: 0
21+
branch_coverage: 95
1922
# 行覆盖率要求 (百分比)
20-
line_coverage: 0
23+
line_coverage: 95
2124

2225
# ============================================================================
2326
# 特定目录的覆盖率要求
2427
# 可以为特定目录设置不同的覆盖率阈值
2528
# ============================================================================
2629
directory_overrides:
27-
# 为除 server 外的所有文件夹设置 0% 覆盖率要求
28-
# 这样可以逐个文件夹增加测试,暂时跳过未测试的文件夹
29-
agentrun/agent_runtime:
30-
full:
31-
branch_coverage: 0
32-
line_coverage: 0
33-
incremental:
34-
branch_coverage: 0
35-
line_coverage: 0
36-
37-
agentrun/credential:
38-
full:
39-
branch_coverage: 0
40-
line_coverage: 0
41-
incremental:
42-
branch_coverage: 0
43-
line_coverage: 0
44-
45-
agentrun/integration:
46-
full:
47-
branch_coverage: 0
48-
line_coverage: 0
49-
incremental:
50-
branch_coverage: 0
51-
line_coverage: 0
52-
53-
agentrun/model:
54-
full:
55-
branch_coverage: 0
56-
line_coverage: 0
57-
incremental:
58-
branch_coverage: 0
59-
line_coverage: 0
60-
61-
agentrun/sandbox:
62-
full:
63-
branch_coverage: 0
64-
line_coverage: 0
65-
incremental:
66-
branch_coverage: 0
67-
line_coverage: 0
68-
69-
agentrun/toolset:
70-
full:
71-
branch_coverage: 0
72-
line_coverage: 0
73-
incremental:
74-
branch_coverage: 0
75-
line_coverage: 0
76-
77-
agentrun/utils:
78-
full:
79-
branch_coverage: 0
80-
line_coverage: 0
81-
incremental:
82-
branch_coverage: 0
83-
line_coverage: 0
84-
85-
# server 模块保持默认的 95% 覆盖率要求
86-
agentrun/server:
87-
full:
88-
branch_coverage: 0
89-
line_coverage: 0
90-
incremental:
91-
branch_coverage: 0
92-
line_coverage: 0
93-
94-
# ============================================================================
95-
# 排除配置
96-
# ============================================================================
97-
98-
# 排除的目录(不计入覆盖率统计)
99-
exclude_directories:
100-
- "tests/"
101-
- "*__pycache__*"
102-
- "*_async_template.py"
103-
- "codegen/"
104-
- "examples/"
105-
- "build/"
106-
- "*.egg-info"
107-
108-
# 排除的文件模式
109-
exclude_patterns:
110-
- "*_test.py"
111-
- "test_*.py"
112-
- "conftest.py"
113-
30+
# 示例:为特定目录设置不同的阈值
31+
# agentrun/some_module:
32+
# full:
33+
# branch_coverage: 90
34+
# line_coverage: 90
35+
# incremental:
36+
# branch_coverage: 95
37+
# line_coverage: 95

pyproject.toml

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ known_third_party = ["alibabacloud_tea_openapi", "alibabacloud_devs20230714", "a
102102
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
103103

104104
[tool.mypy]
105-
python_version = "0.0.9"
105+
python_version = "3.10"
106106
exclude = "tests/"
107107
plugins = ["pydantic.mypy"]
108108
# Start with non-strict mode, and switch to strict mode later.
@@ -115,6 +115,76 @@ testpaths = ["tests"]
115115
asyncio_default_fixture_loop_scope = "function"
116116
asyncio_mode = "auto"
117117

118+
# ============================================================================
119+
# Coverage.py 配置
120+
# ============================================================================
121+
[tool.coverage.run]
122+
# 源代码目录
123+
source = ["agentrun"]
124+
# 启用分支覆盖率
125+
branch = true
126+
# 排除的文件模式
127+
omit = [
128+
# 包初始化文件(主要是导出和延迟加载逻辑)
129+
"agentrun/__init__.py",
130+
# 测试文件
131+
"*/tests/*",
132+
"*_test.py",
133+
"test_*.py",
134+
"conftest.py",
135+
# 模板文件(用于代码生成)
136+
"*_async_template.py",
137+
"*__async_template.py",
138+
# 自动生成的 API 控制代码
139+
"*/api/control.py",
140+
# 代码生成和构建目录
141+
"codegen/*",
142+
"examples/*",
143+
"build/*",
144+
"*.egg-info/*",
145+
# 缓存目录
146+
"*__pycache__*",
147+
# server 和 sandbox 模块
148+
"agentrun/server/*",
149+
"agentrun/sandbox/*",
150+
# integration 模块(第三方集成,单独测试)
151+
"agentrun/integration/*",
152+
# MCP 客户端(需要外部 MCP 服务器)
153+
"agentrun/toolset/api/mcp.py",
154+
# OpenAPI 解析器(复杂的 HTTP/schema mocking)
155+
"agentrun/toolset/api/openapi.py",
156+
# 客户端模块(异步方法与同步方法逻辑相同,单测同步方法即可)
157+
"agentrun/agent_runtime/client.py",
158+
"agentrun/model/client.py",
159+
"agentrun/credential/client.py",
160+
# endpoint 模块(invoke_openai 需要 Data API,难以单测)
161+
"agentrun/agent_runtime/endpoint.py",
162+
# toolset 模块(call_tool 和 to_apiset 需要外部 API 调用)
163+
"agentrun/toolset/toolset.py",
164+
# runtime 模块(invoke_openai 需要 Data API)
165+
"agentrun/agent_runtime/runtime.py",
166+
]
167+
168+
[tool.coverage.report]
169+
# 排除的代码行模式
170+
exclude_lines = [
171+
# 标准排除
172+
"pragma: no cover",
173+
# 类型检查导入
174+
"if TYPE_CHECKING:",
175+
# 调试断言
176+
"raise AssertionError",
177+
"raise NotImplementedError",
178+
# 抽象方法
179+
"@abstractmethod",
180+
# 防御性断言
181+
"if __name__ == .__main__.:",
182+
]
183+
# 显示缺失的行
184+
show_missing = true
185+
# 精度
186+
precision = 2
187+
118188
[tool.setuptools.packages.find]
119189
where = ["."]
120190
include = ["agentrun*", "alibabacloud_agentrun20250910*"] # 包含子包和子模块,排除 codegen
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Agent Runtime 单元测试模块"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Agent Runtime API 单元测试模块"""

0 commit comments

Comments
 (0)