-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests_with_coverage.py
More file actions
executable file
·102 lines (80 loc) · 3.09 KB
/
Copy pathrun_tests_with_coverage.py
File metadata and controls
executable file
·102 lines (80 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
Test runner with coverage reporting.
Run this script to execute all tests and generate coverage reports.
Usage:
python run_tests_with_coverage.py [options]
Options:
--unit Run only unit tests
--integration Run only integration tests
--smoke Run only smoke tests
--html Generate HTML coverage report
--open Open HTML report in browser (requires --html)
--min-coverage Set minimum coverage percentage (default: 80)
"""
import sys
import subprocess
import argparse
import webbrowser
from pathlib import Path
def run_command(cmd, description):
"""Run a command and return success status."""
print(f"\n🔄 {description}")
print(f"Running: {' '.join(cmd)}")
# Run with real-time output for better visibility
result = subprocess.run(cmd)
if result.returncode == 0:
print(f"✅ {description} - PASSED")
else:
print(f"❌ {description} - FAILED")
return result.returncode == 0
def main():
parser = argparse.ArgumentParser(description="Run tests with coverage")
parser.add_argument("--unit", action="store_true", help="Run only unit tests")
parser.add_argument("--integration", action="store_true", help="Run only integration tests")
parser.add_argument("--smoke", action="store_true", help="Run only smoke tests")
parser.add_argument("--html", action="store_true", help="Generate HTML coverage report")
parser.add_argument("--open", action="store_true", help="Open HTML report in browser")
parser.add_argument("--min-coverage", type=float, default=80.0, help="Minimum coverage percentage")
args = parser.parse_args()
# Determine test paths
if args.unit:
test_paths = ["tests/unit/"]
elif args.integration:
test_paths = ["tests/integration/"]
elif args.smoke:
test_paths = ["tests/smoke/"]
else:
test_paths = ["tests/"]
# Build pytest command
cmd = ["python", "-m", "pytest"]
cmd.extend(test_paths)
# Add coverage options
cmd.extend([
"--cov=ai_shell_command_generator",
"--cov-report=term-missing",
f"--cov-fail-under={args.min_coverage}"
])
if args.html:
cmd.append("--cov-report=html")
# Run tests
success = run_command(cmd, "Running tests with coverage")
if success and args.html:
html_dir = Path("htmlcov")
index_file = html_dir / "index.html"
if index_file.exists():
print(f"\n📊 HTML coverage report generated: {index_file.absolute()}")
if args.open:
print("🌐 Opening coverage report in browser...")
webbrowser.open(f"file://{index_file.absolute()}")
else:
print("⚠️ HTML coverage report not found")
# Summary
if success:
print(f"\n🎉 All tests passed with coverage >= {args.min_coverage}%")
return 0
else:
print(f"\n💥 Tests failed or coverage < {args.min_coverage}%")
return 1
if __name__ == "__main__":
sys.exit(main())