Commit 576b7552 authored by wooway777's avatar wooway777 Committed by MaYuhang
Browse files

issue/573 - improved run.py

parent 6dccaed2
...@@ -6,28 +6,19 @@ from pathlib import Path ...@@ -6,28 +6,19 @@ from pathlib import Path
from typing import Dict, Tuple, List from typing import Dict, Tuple, List
def find_ops_directory(start_dir=None): def find_ops_directory(location=None):
""" """
Find the ops directory by searching from start_dir upwards. Find the ops directory by searching from location upwards.
Args: Args:
start_dir: Starting directory for search (default: current file's parent) location: Starting directory for search (default: current file's parent)
Returns: Returns:
Path: Path to ops directory or None if not found Path: Path to ops directory or None if not found
""" """
if start_dir is None: if location is None:
start_dir = Path(__file__).parent location = Path(__file__).parent / "ops"
# Look for ops directory in common locations
possible_locations = [
start_dir / "ops",
start_dir / ".." / "ops",
start_dir / ".." / "test" / "ops",
start_dir / "test" / "ops",
]
for location in possible_locations:
ops_dir = location.resolve() ops_dir = location.resolve()
if ops_dir.exists() and any(ops_dir.glob("*.py")): if ops_dir.exists() and any(ops_dir.glob("*.py")):
return ops_dir return ops_dir
...@@ -116,7 +107,7 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None): ...@@ -116,7 +107,7 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None):
filtered_files = [] filtered_files = []
for test_file in operator_test_files: for test_file in operator_test_files:
test_name = test_file.stem.lower() test_name = test_file.stem.lower()
if any(op.lower() in test_name for op in specific_ops): if any(op.lower() == test_name for op in specific_ops):
filtered_files.append(test_file) filtered_files.append(test_file)
operator_test_files = filtered_files operator_test_files = filtered_files
...@@ -135,8 +126,8 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None): ...@@ -135,8 +126,8 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None):
test_name = test_file.stem test_name = test_file.stem
try: try:
# Run the test script # Run the test script - use the absolute path and run from current directory
cmd = [sys.executable, str(test_file)] cmd = [sys.executable, str(test_file.absolute())]
# Add extra arguments if provided # Add extra arguments if provided
if extra_args: if extra_args:
...@@ -144,7 +135,6 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None): ...@@ -144,7 +135,6 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None):
result = subprocess.run( result = subprocess.run(
cmd, cmd,
cwd=ops_dir,
capture_output=True, # Capture output to analyze capture_output=True, # Capture output to analyze
text=True, text=True,
) )
...@@ -154,22 +144,23 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None): ...@@ -154,22 +144,23 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None):
stderr_lower = result.stderr.lower() stderr_lower = result.stderr.lower()
# Check for operator not implemented patterns # Check for operator not implemented patterns
if "not implemented" in stdout_lower or "not implemented" in stderr_lower: if (
if "both operators not implemented" in stdout_lower: "all tests passed!" in stdout_lower
and "success rate: 100.0%" in stdout_lower
):
success = True
returncode = 0
elif "both operators not implemented" in stdout_lower:
# Both operators not implemented - skipped test # Both operators not implemented - skipped test
success = True # Not a failure, but skipped success = False # Not a failure, but skipped
returncode = -2 # Special code for skipped returncode = -2 # Special code for skipped
elif "one operator not implemented" in stdout_lower: elif "one operator not implemented" in stdout_lower:
# One operator not implemented - partial test # One operator not implemented - partial test
success = False # Not fully successful success = False # Not fully successful
returncode = -3 # Special code for partial returncode = -3 # Special code for partial
else: else:
# General not implemented case success = False
success = result.returncode == 0 returncode = -1
returncode = result.returncode
else:
success = result.returncode == 0
returncode = result.returncode
results[test_name] = ( results[test_name] = (
success, success,
...@@ -193,10 +184,10 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None): ...@@ -193,10 +184,10 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None):
# Enhanced status display # Enhanced status display
if returncode == -2: if returncode == -2:
status_icon = "⏭️" status_icon = "⏭️"
status_text = "SKIPPED (operators not implemented)" status_text = "SKIPPED"
elif returncode == -3: elif returncode == -3:
status_icon = "⚠️" status_icon = "⚠️"
status_text = "PARTIAL (one operator not implemented)" status_text = "PARTIAL"
elif success: elif success:
status_icon = "✅" status_icon = "✅"
status_text = "PASSED" status_text = "PASSED"
...@@ -218,7 +209,7 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None): ...@@ -218,7 +209,7 @@ def run_all_op_tests(ops_dir=None, specific_ops=None, extra_args=None):
def print_summary(results): def print_summary(results):
"""Print a comprehensive summary of test results.""" """Print a comprehensive summary of test results."""
print(f"\n{'='*80}") print(f"\n{'='*80}")
print("TEST SUMMARY") print("CUMULATIVE TEST SUMMARY")
print(f"{'='*80}") print(f"{'='*80}")
if not results: if not results:
...@@ -230,16 +221,24 @@ def print_summary(results): ...@@ -230,16 +221,24 @@ def print_summary(results):
failed = 0 failed = 0
skipped = 0 skipped = 0
partial = 0 partial = 0
passed_operators = [] # Store passed operator names
failed_operators = [] # Store failed operator names
skipped_operators = [] # Store skipped operator names
partial_operators = [] # Store partial operator names
for test_name, (success, returncode, stdout, stderr) in results.items(): for test_name, (success, returncode, stdout, stderr) in results.items():
if success: if success:
passed += 1 passed += 1
passed_operators.append(test_name)
elif returncode == -2: # Special code for skipped tests elif returncode == -2: # Special code for skipped tests
skipped += 1 skipped += 1
skipped_operators.append(test_name)
elif returncode == -3: # Special code for partial tests elif returncode == -3: # Special code for partial tests
partial += 1 partial += 1
partial_operators.append(test_name)
else: else:
failed += 1 failed += 1
failed_operators.append(test_name)
total = len(results) total = len(results)
...@@ -248,17 +247,48 @@ def print_summary(results): ...@@ -248,17 +247,48 @@ def print_summary(results):
print(f"Failed: {failed}") print(f"Failed: {failed}")
if skipped > 0: if skipped > 0:
print(f"Skipped (operators not implemented): {skipped}") print(f"Skipped: {skipped}")
if partial > 0: if partial > 0:
print(f"Partial (one operator not implemented): {partial}") print(f"Partial: {partial}")
# Display passed operators
if passed_operators:
print(f"\n✅ PASSED OPERATORS ({len(passed_operators)}):")
# Display operators in groups of 10 per line
for i in range(0, len(passed_operators), 10):
line_ops = passed_operators[i : i + 10]
print(" " + ", ".join(line_ops))
else:
print(f"\n✅ PASSED OPERATORS: None")
# Display failed operators (if any)
if failed_operators:
print(f"\n❌ FAILED OPERATORS ({len(failed_operators)}):")
for i in range(0, len(failed_operators), 10):
line_ops = failed_operators[i : i + 10]
print(" " + ", ".join(line_ops))
# Display skipped operators (if any)
if skipped_operators:
print(f"\n⏭️ SKIPPED OPERATORS ({len(skipped_operators)}):")
for i in range(0, len(skipped_operators), 10):
line_ops = skipped_operators[i : i + 10]
print(" " + ", ".join(line_ops))
# Display partial operators (if any)
if partial_operators:
print(f"\n⚠️ PARTIAL OPERATORS ({len(partial_operators)}):")
for i in range(0, len(partial_operators), 10):
line_ops = partial_operators[i : i + 10]
print(" " + ", ".join(line_ops))
if total > 0: if total > 0:
# Calculate success rate based on executed tests only # Calculate success rate based on executed tests only
executed_tests = passed + failed + partial executed_tests = passed + failed + partial
if executed_tests > 0: if executed_tests > 0:
success_rate = passed / executed_tests * 100 success_rate = passed / executed_tests * 100
print(f"Success rate: {success_rate:.1f}%") print(f"\nSuccess rate: {success_rate:.1f}%")
if failed == 0: if failed == 0:
if skipped > 0 or partial > 0: if skipped > 0 or partial > 0:
...@@ -269,10 +299,7 @@ def print_summary(results): ...@@ -269,10 +299,7 @@ def print_summary(results):
print(f"\n🎉 All tests passed!") print(f"\n🎉 All tests passed!")
return True return True
else: else:
print(f"\n{failed} tests failed:") print(f"\n{failed} tests failed")
for test_name, (success, returncode, stdout, stderr) in results.items():
if not success and returncode not in [-2, -3]: # Not skipped or partial
print(f" - {test_name} (return code: {returncode})")
return False return False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment