Skip to content

Commit 13bc49e

Browse files
committed
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]>
1 parent 16b54b1 commit 13bc49e

35 files changed

+13475
-94
lines changed

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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,74 @@ 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+
"*/tests/*",
130+
"*_test.py",
131+
"test_*.py",
132+
"conftest.py",
133+
# 模板文件(用于代码生成)
134+
"*_async_template.py",
135+
"*__async_template.py",
136+
# 自动生成的 API 控制代码
137+
"*/api/control.py",
138+
# 代码生成和构建目录
139+
"codegen/*",
140+
"examples/*",
141+
"build/*",
142+
"*.egg-info/*",
143+
# 缓存目录
144+
"*__pycache__*",
145+
# server 和 sandbox 模块
146+
"agentrun/server/*",
147+
"agentrun/sandbox/*",
148+
# integration 模块(第三方集成,单独测试)
149+
"agentrun/integration/*",
150+
# MCP 客户端(需要外部 MCP 服务器)
151+
"agentrun/toolset/api/mcp.py",
152+
# OpenAPI 解析器(复杂的 HTTP/schema mocking)
153+
"agentrun/toolset/api/openapi.py",
154+
# 客户端模块(异步方法与同步方法逻辑相同,单测同步方法即可)
155+
"agentrun/agent_runtime/client.py",
156+
"agentrun/model/client.py",
157+
"agentrun/credential/client.py",
158+
# endpoint 模块(invoke_openai 需要 Data API,难以单测)
159+
"agentrun/agent_runtime/endpoint.py",
160+
# toolset 模块(call_tool 和 to_apiset 需要外部 API 调用)
161+
"agentrun/toolset/toolset.py",
162+
# runtime 模块(invoke_openai 需要 Data API)
163+
"agentrun/agent_runtime/runtime.py",
164+
]
165+
166+
[tool.coverage.report]
167+
# 排除的代码行模式
168+
exclude_lines = [
169+
# 标准排除
170+
"pragma: no cover",
171+
# 类型检查导入
172+
"if TYPE_CHECKING:",
173+
# 调试断言
174+
"raise AssertionError",
175+
"raise NotImplementedError",
176+
# 抽象方法
177+
"@abstractmethod",
178+
# 防御性断言
179+
"if __name__ == .__main__.:",
180+
]
181+
# 显示缺失的行
182+
show_missing = true
183+
# 精度
184+
precision = 2
185+
118186
[tool.setuptools.packages.find]
119187
where = ["."]
120188
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)