forked from deepseek-ai/TileKernels
-
Notifications
You must be signed in to change notification settings - Fork 7
增加算子测试清单 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghangz
wants to merge
2
commits into
MetaX-MACA:dev
Choose a base branch
from
ghangz:mengz/tilekernels-test-inventory
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
增加算子测试清单 #9
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env python3 | ||
| """Create a JSON inventory of TileKernels test files by operator area.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| from collections import defaultdict | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def build_inventory(root: Path) -> dict[str, object]: | ||
| groups: dict[str, list[str]] = defaultdict(list) | ||
| tests_dir = root / "tests" | ||
| if not tests_dir.is_dir(): | ||
| return {"total": 0, "groups": {}} | ||
|
|
||
| for path in sorted(tests_dir.rglob("test_*.py")): | ||
| rel = path.relative_to(root).as_posix() | ||
| parts = path.relative_to(tests_dir).parts | ||
| group = parts[0] if len(parts) > 1 else "root" | ||
| groups[group].append(rel) | ||
| return { | ||
| "total": sum(len(items) for items in groups.values()), | ||
| "groups": {name: {"count": len(items), "files": items} for name, items in sorted(groups.items())}, | ||
| } | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description="List TileKernels tests by area.") | ||
| parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) | ||
| parser.add_argument("--output", type=Path) | ||
| args = parser.parse_args() | ||
|
|
||
| text = json.dumps(build_inventory(args.root.resolve()), indent=2, sort_keys=True) | ||
| if args.output: | ||
| args.output.parent.mkdir(parents=True, exist_ok=True) | ||
| args.output.write_text(text + "\n", encoding="utf-8") | ||
| else: | ||
| print(text) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from pathlib import Path | ||
|
|
||
| from scripts.test_inventory import build_inventory | ||
|
|
||
|
|
||
| def test_build_inventory_groups_nested_tests(tmp_path: Path): | ||
| test_dir = tmp_path / "tests" / "moe" | ||
| test_dir.mkdir(parents=True) | ||
| (test_dir / "test_gate.py").write_text("", encoding="utf-8") | ||
|
|
||
| inventory = build_inventory(tmp_path) | ||
|
|
||
| assert inventory["total"] == 1 | ||
| assert inventory["groups"]["moe"]["files"] == ["tests/moe/test_gate.py"] | ||
|
|
||
|
|
||
| def test_build_inventory_handles_missing_tests_dir(tmp_path: Path): | ||
| inventory = build_inventory(tmp_path) | ||
|
|
||
| assert inventory["total"] == 0 | ||
| assert inventory["groups"] == {} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议增加一个测试用例,用于验证当
tests目录不存在时,build_inventory能够安全返回空的总览结构而不抛出异常。