This repository was archived by the owner on Apr 23, 2025. It is now read-only.
forked from raizamartin/gemini-code
-
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
·92 lines (70 loc) · 2.9 KB
/
run_tests_with_coverage.py
File metadata and controls
executable file
·92 lines (70 loc) · 2.9 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
#!/usr/bin/env python
"""
Script to run tests with coverage reporting.
This script makes it easy to run the test suite with coverage reporting
and see which parts of the code need more test coverage.
Usage:
python run_tests_with_coverage.py
"""
import os
import sys
import subprocess
import argparse
import webbrowser
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description="Run tests with coverage reporting")
parser.add_argument("--html", action="store_true", help="Open HTML report after running")
parser.add_argument("--xml", action="store_true", help="Generate XML report")
parser.add_argument("--skip-tests", action="store_true", help="Skip running tests and just report on existing coverage data")
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
args = parser.parse_args()
# Get the root directory of the project
root_dir = Path(__file__).parent
# Change to the root directory
os.chdir(root_dir)
# Add the src directory to Python path to ensure proper imports
sys.path.insert(0, str(root_dir / 'src'))
if not args.skip_tests:
# Ensure we have the necessary packages
print("Installing required packages...")
subprocess.run([sys.executable, "-m", "pip", "install", "pytest", "pytest-cov"],
check=False)
# Run pytest with coverage
print("\nRunning tests with coverage...")
cmd = [
sys.executable, "-m", "pytest",
"--cov=cli_code",
"--cov-report=term",
]
# Add XML report if requested
if args.xml:
cmd.append("--cov-report=xml")
# Always generate HTML report
cmd.append("--cov-report=html")
# Add verbosity if requested
if args.verbose:
cmd.append("-v")
# Run tests
result = subprocess.run(cmd + ["test_dir/"], check=False)
if result.returncode != 0:
print("\n⚠️ Some tests failed! See above for details.")
else:
print("\n✅ All tests passed!")
# Parse coverage results
try:
html_report = root_dir / "coverage_html" / "index.html"
if html_report.exists():
if args.html:
print(f"\nOpening HTML coverage report: {html_report}")
webbrowser.open(f"file://{html_report.absolute()}")
else:
print(f"\nHTML coverage report available at: file://{html_report.absolute()}")
xml_report = root_dir / "coverage.xml"
if args.xml and xml_report.exists():
print(f"XML coverage report available at: {xml_report}")
except Exception as e:
print(f"Error processing coverage reports: {e}")
print("\nDone!")
if __name__ == "__main__":
main()