From b0d450b1388c6edcd761fa9a8627936129ac8bdc Mon Sep 17 00:00:00 2001 From: papertager <2567587994@qq.com> Date: Tue, 9 Jun 2026 21:27:07 +0800 Subject: [PATCH 1/2] Add TileKernels test inventory helper --- scripts/test_inventory.py | 41 ++++++++++++++++++++++++++++++++++++ tests/test_test_inventory.py | 14 ++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 scripts/test_inventory.py create mode 100644 tests/test_test_inventory.py diff --git a/scripts/test_inventory.py b/scripts/test_inventory.py new file mode 100644 index 0000000..fb46cbd --- /dev/null +++ b/scripts/test_inventory.py @@ -0,0 +1,41 @@ +#!/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) + for path in sorted((root / "tests").rglob("test_*.py")): + rel = path.relative_to(root).as_posix() + parts = path.relative_to(root / "tests").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()) diff --git a/tests/test_test_inventory.py b/tests/test_test_inventory.py new file mode 100644 index 0000000..9b348d2 --- /dev/null +++ b/tests/test_test_inventory.py @@ -0,0 +1,14 @@ +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"] From cbd2d9eaae4dd37a498652c20ae5cae2a54f7b94 Mon Sep 17 00:00:00 2001 From: mengz <2567587994@qq.com> Date: Wed, 10 Jun 2026 23:53:36 +0800 Subject: [PATCH 2/2] Handle missing TileKernels tests directory --- scripts/test_inventory.py | 8 ++++++-- tests/test_test_inventory.py | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/test_inventory.py b/scripts/test_inventory.py index fb46cbd..39bf64e 100644 --- a/scripts/test_inventory.py +++ b/scripts/test_inventory.py @@ -11,9 +11,13 @@ def build_inventory(root: Path) -> dict[str, object]: groups: dict[str, list[str]] = defaultdict(list) - 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")): rel = path.relative_to(root).as_posix() - parts = path.relative_to(root / "tests").parts + parts = path.relative_to(tests_dir).parts group = parts[0] if len(parts) > 1 else "root" groups[group].append(rel) return { diff --git a/tests/test_test_inventory.py b/tests/test_test_inventory.py index 9b348d2..f750b2d 100644 --- a/tests/test_test_inventory.py +++ b/tests/test_test_inventory.py @@ -12,3 +12,10 @@ def test_build_inventory_groups_nested_tests(tmp_path: 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"] == {}