All checks were successful
Python CI / test (push) Successful in 42s
Remove: Un-used funcs
109 lines
3.6 KiB
Python
109 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Local coverage runner script.
|
|
Runs test and documentation coverage locally and generates badges.
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
|
|
def run_command(cmd, description):
|
|
"""Run a command and handle errors."""
|
|
print(f"\n{'='*50}")
|
|
print(f"Running: {description}")
|
|
print(f"Command: {cmd}")
|
|
print(f"{'='*50}")
|
|
|
|
try:
|
|
result = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
|
|
print(result.stdout)
|
|
if result.stderr:
|
|
print("STDERR:", result.stderr)
|
|
return True
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Error running {description}:")
|
|
print(f"Return code: {e.returncode}")
|
|
print(f"STDOUT: {e.stdout}")
|
|
print(f"STDERR: {e.stderr}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Run full coverage analysis locally."""
|
|
print("Local Coverage Analysis for pyWebLayout")
|
|
print("=" * 60)
|
|
|
|
# Change to project root if running from scripts directory
|
|
if os.path.basename(os.getcwd()) == "scripts":
|
|
os.chdir("..")
|
|
|
|
# Install required packages
|
|
print("\n1. Installing required packages...")
|
|
packages = [
|
|
"pytest pytest-cov",
|
|
"coverage-badge",
|
|
"interrogate"
|
|
]
|
|
|
|
for package in packages:
|
|
if not run_command(f"pip install {package}", f"Installing {package}"):
|
|
print(f"Failed to install {package}, continuing...")
|
|
|
|
# Run tests with coverage
|
|
print("\n2. Running tests with coverage...")
|
|
test_cmd = "python -m pytest tests/ -v --cov=pyWebLayout --cov-report=term-missing --cov-report=json --cov-report=html --cov-report=xml"
|
|
run_command(test_cmd, "Running tests with coverage")
|
|
|
|
# Generate test coverage badge
|
|
print("\n3. Generating test coverage badge...")
|
|
run_command("coverage-badge -o coverage.svg", "Generating test coverage badge")
|
|
|
|
# Check documentation coverage
|
|
print("\n4. Checking documentation coverage...")
|
|
docs_cmd = "interrogate -v --ignore-init-method --ignore-init-module --ignore-magic --ignore-private --ignore-property-decorators --ignore-semiprivate --fail-under=80 --generate-badge coverage-docs.svg pyWebLayout/"
|
|
run_command(docs_cmd, "Checking documentation coverage")
|
|
|
|
# Generate coverage summary
|
|
print("\n5. Generating coverage summary...")
|
|
summary_script = """
|
|
import json
|
|
import os
|
|
|
|
if os.path.exists('coverage.json'):
|
|
with open('coverage.json', 'r') as f:
|
|
coverage_data = json.load(f)
|
|
|
|
total_coverage = round(coverage_data['totals']['percent_covered'], 1)
|
|
|
|
with open('coverage-summary.txt', 'w') as f:
|
|
f.write(f'{total_coverage}%')
|
|
|
|
print(f'Test Coverage: {total_coverage}%')
|
|
print(f'Lines Covered: {coverage_data["totals"]["covered_lines"]}/{coverage_data["totals"]["num_statements"]}')
|
|
else:
|
|
print('No coverage data found')
|
|
"""
|
|
run_command(f'python -c "{summary_script}"', "Generating coverage summary")
|
|
|
|
# List generated files
|
|
print("\n6. Generated files:")
|
|
files = ["coverage.svg", "coverage-docs.svg", "coverage-summary.txt", "htmlcov/", "coverage.json", "coverage.xml"]
|
|
for file in files:
|
|
if os.path.exists(file):
|
|
print(f" ✓ {file}")
|
|
else:
|
|
print(f" ✗ {file} (not found)")
|
|
|
|
print("\n" + "="*60)
|
|
print("Coverage analysis complete!")
|
|
print("To update your README with badges, run:")
|
|
print(" python scripts/update_coverage_badges.py")
|
|
print("\nTo view detailed HTML coverage report:")
|
|
print(" open htmlcov/index.html")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|