Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a script to generate a JSON inventory of test files grouped by operator area, along with corresponding unit tests. The review feedback suggests improving robustness by handling cases where the "tests" directory does not exist in the target root, and adding a test case to verify this behavior.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| def build_inventory(root: Path) -> dict[str, object]: | ||
| groups: dict[str, list[str]] = defaultdict(list) | ||
| for path in sorted((root / "tests").rglob("test_*.py")): |
There was a problem hiding this comment.
如果指定的 root 目录下不存在 tests 子目录,对 rglob 的结果进行迭代(例如通过 sorted(...))会抛出 FileNotFoundError 异常。为了提高代码的健壮性,建议在遍历前先检查 tests 目录是否存在。如果不存在,可以直接返回一个空的总览结构。
| for path in sorted((root / "tests").rglob("test_*.py")): | |
| tests_dir = root / "tests" | |
| if not tests_dir.is_dir(): | |
| return {"total": 0, "groups": {}} | |
| for path in sorted(tests_dir.rglob("test_*.py")): |
| inventory = build_inventory(tmp_path) | ||
|
|
||
| assert inventory["total"] == 1 | ||
| assert inventory["groups"]["moe"]["files"] == ["tests/moe/test_gate.py"] |
There was a problem hiding this comment.
建议增加一个测试用例,用于验证当 tests 目录不存在时,build_inventory 能够安全返回空的总览结构而不抛出异常。
| assert inventory["groups"]["moe"]["files"] == ["tests/moe/test_gate.py"] | |
| assert inventory["groups"]["moe"]["files"] == ["tests/moe/test_gate.py"] | |
| def test_build_inventory_no_tests_dir(tmp_path: Path): | |
| inventory = build_inventory(tmp_path) | |
| assert inventory["total"] == 0 | |
| assert inventory["groups"] == {} |
这次改动补上了算子测试清单,主要是为了解决算子测试与维护流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。
实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。
这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。