Skip to content

Commit 20b9048

Browse files
authored
fix(plugin_test): 修复插件测试日志不全时版本号匹配失败的问题 (#300)
1 parent b85601f commit 20b9048

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
1010
### Fixed
1111

1212
- 修复 Docker Test 报错后仍无法运行的问题
13+
- 修复插件测试日志不全时版本号匹配失败的问题
1314

1415
## [4.1.0] - 2024-11-28
1516

src/providers/docker_test/plugin_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def extract_version(output: str, project_link: str) -> str | None:
203203
if match:
204204
return match.group(1).strip()
205205

206+
match = re.search(rf"- Installing {project_link} \((\S+)\)", output)
207+
if match:
208+
return match.group(1).strip()
209+
206210

207211
def parse_requirements(requirements: str) -> dict[str, str]:
208212
"""解析 requirements.txt 文件"""
@@ -326,12 +330,9 @@ async def command(self, cmd: str, timeout: int = 300) -> tuple[bool, str, str]:
326330
except TimeoutError:
327331
proc.terminate()
328332
# 超时后仍需读取 stdout 与 stderr 的内容
329-
stdout = await proc.stdout.read() if proc.stdout else b""
330-
stderr = (
331-
"执行命令超时".encode() + await proc.stderr.read()
332-
if proc.stderr
333-
else "执行命令超时".encode()
334-
)
333+
stdout = "执行命令超时\n".encode()
334+
stdout += await proc.stdout.read() if proc.stdout else b""
335+
stderr = await proc.stderr.read() if proc.stderr else b""
335336
code = 1
336337

337338
return not code, stdout.decode(), stderr.decode()

tests/utils/docker_test/test_extract_version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,27 @@ def test_extract_version_install_failed(tmp_path: Path):
113113
version = extract_version(output, "nonebot2")
114114

115115
assert version is None
116+
117+
118+
def test_extract_version_install_failed_partial_output(tmp_path: Path):
119+
"""安装插件失败的情况,输出不知道为什么只剩下了部分
120+
121+
TODO: 弄清楚为什么输出不完整。
122+
"""
123+
from src.providers.docker_test.plugin_test import extract_version
124+
125+
output = """
126+
项目 nonebot-plugin-todo-nlp 创建失败:
127+
执行命令超时
128+
- Installing nonebot-plugin-todo-nlp (0.1.9)
129+
130+
Writing lock file
131+
"""
132+
133+
version = extract_version(output, "nonebot-plugin-todo-nlp")
134+
135+
assert version == "0.1.9"
136+
137+
version = extract_version(output, "nonebot2")
138+
139+
assert version is None

0 commit comments

Comments
 (0)