-
Notifications
You must be signed in to change notification settings - Fork 86
issue/787 - Split run ops test logic and fix kwargs name in report #788
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||
| import torch | ||||
| import infinicore | ||||
|
|
||||
| from dataclasses import dataclass, field | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 删? |
||||
|
|
||||
|
Comment on lines
+3
to
4
|
||||
| from dataclasses import dataclass, field |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||
| import sys | ||||||
| import importlib.util | ||||||
| from io import StringIO | ||||||
| from contextlib import contextmanager | ||||||
| from .types import OperatorTestResult, TestTiming | ||||||
|
||||||
| from .types import OperatorTestResult, TestTiming | |
| from .types import OperatorTestResult |
baominghelly marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| class TestDiscoverer: | ||||||
| def __init__(self, ops_dir_path=None): | ||||||
| self.ops_dir = self._resolve_dir(ops_dir_path) | ||||||
|
|
||||||
| def _resolve_dir(self, path): | ||||||
| if path: | ||||||
| p = Path(path) | ||||||
| if p.exists(): return p | ||||||
|
|
||||||
| # Default fallback logic: 'ops' directory under the parent of the current file's parent. | ||||||
| # Note: Since this file is in 'framework/', we look at parent.parent. | ||||||
| # It is recommended to pass an explicit path in run.py. | ||||||
| fallback = Path(__file__).parent.parent / "ops" | ||||||
| return fallback if fallback.exists() else None | ||||||
|
|
||||||
| def get_available_operators(self): | ||||||
| """Returns a list of names of all available operators.""" | ||||||
| if not self.ops_dir: return [] | ||||||
| files = self.scan() | ||||||
| return sorted([f.stem for f in files]) | ||||||
|
|
||||||
| def get_raw_python_files(self): | ||||||
| """ | ||||||
| Get all .py files in the directory (excluding run.py) without content validation. | ||||||
| Used for debugging: helps identify files that exist but failed validation. | ||||||
| """ | ||||||
| if not self.ops_dir or not self.ops_dir.exists(): | ||||||
| return [] | ||||||
|
|
||||||
| files = list(self.ops_dir.glob("*.py")) | ||||||
| # Exclude run.py itself and __init__.py | ||||||
| return [f.name for f in files if f.name != "run.py" and not f.name.startswith("__")] | ||||||
|
|
||||||
| def scan(self, specific_ops=None): | ||||||
| """Scans and returns a list of Path objects that meet the criteria.""" | ||||||
| if not self.ops_dir or not self.ops_dir.exists(): | ||||||
| return [] | ||||||
|
|
||||||
| # 1. Find all .py files | ||||||
| files = list(self.ops_dir.glob("*.py")) | ||||||
|
|
||||||
| target_ops_set = set(specific_ops) if specific_ops else None | ||||||
|
|
||||||
| # 2. Filter out non-test files (via content check) | ||||||
| valid_files = [] | ||||||
| for f in files: | ||||||
| # A. Basic Name Filtering | ||||||
| if f.name.startswith("_") or f.name == "run.py": | ||||||
| continue | ||||||
|
|
||||||
| # B. Specific Ops Filtering | ||||||
| if target_ops_set and f.stem not in target_ops_set: | ||||||
| continue | ||||||
|
|
||||||
| # C. Content Check (Expensive I/O) | ||||||
| # Only perform this check if the file passed the name filters above. | ||||||
| if self._is_operator_test(f): | ||||||
| valid_files.append(f) | ||||||
|
|
||||||
| return valid_files | ||||||
|
|
||||||
| def _is_operator_test(self, file_path): | ||||||
| """Checks if the file content contains operator test characteristics.""" | ||||||
| try: | ||||||
| with open(file_path, "r", encoding="utf-8") as f: | ||||||
| content = f.read() | ||||||
| return "infinicore" in content and ( | ||||||
| "BaseOperatorTest" in content or "GenericTestRunner" in content | ||||||
| ) | ||||||
| except: | ||||||
|
||||||
| except: | |
| except Exception: |
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.
Import of 'TestCase' is not used.