[WIP] Add tests and coverage
This commit is contained in:
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
"""
|
||||
Automated coverage testing script for the gallery generator.
|
||||
This script runs tests with coverage analysis and generates comprehensive reports.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_coverage_tests():
|
||||
"""Run tests with coverage analysis."""
|
||||
print("🔬 Starting automated coverage testing...")
|
||||
|
||||
# Ensure we're in the right directory
|
||||
os.chdir('/src' if Path('/src').exists() else Path(__file__).parent.parent)
|
||||
|
||||
# Remove old coverage data
|
||||
subprocess.run(['coverage', 'erase'], capture_output=True)
|
||||
|
||||
# Run tests with coverage
|
||||
print("📊 Running tests with coverage analysis...")
|
||||
|
||||
test_files = [
|
||||
'tests/test_simple_coverage.py',
|
||||
'tests/test_container.py',
|
||||
'tests/test_build_container.py'
|
||||
]
|
||||
|
||||
success = True
|
||||
for test_file in test_files:
|
||||
if Path(test_file).exists():
|
||||
print(f" Running {test_file}...")
|
||||
result = subprocess.run([
|
||||
'coverage', 'run', '--append', '-m', 'unittest',
|
||||
test_file.replace('/', '.').replace('.py', '')
|
||||
], capture_output=True, text=True)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"❌ Failed: {test_file}")
|
||||
print(f"Error: {result.stderr}")
|
||||
success = False
|
||||
else:
|
||||
print(f"✅ Passed: {test_file}")
|
||||
|
||||
if not success:
|
||||
print("❌ Some tests failed. Coverage report may be incomplete.")
|
||||
return False
|
||||
|
||||
# Generate coverage reports
|
||||
print("\n📈 Generating coverage reports...")
|
||||
|
||||
# Console report
|
||||
print("\n🖥️ Console Coverage Report:")
|
||||
subprocess.run(['coverage', 'report'])
|
||||
|
||||
# HTML report
|
||||
html_result = subprocess.run(['coverage', 'html'], capture_output=True, text=True)
|
||||
if html_result.returncode == 0:
|
||||
print("\n🌐 HTML coverage report generated: coverage_html_report/index.html")
|
||||
|
||||
# XML report for CI/CD
|
||||
xml_result = subprocess.run(['coverage', 'xml'], capture_output=True, text=True)
|
||||
if xml_result.returncode == 0:
|
||||
print("📄 XML coverage report generated: coverage.xml")
|
||||
|
||||
# Coverage percentage
|
||||
percentage_result = subprocess.run([
|
||||
'coverage', 'report', '--format=total'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
if percentage_result.returncode == 0:
|
||||
try:
|
||||
coverage_pct = float(percentage_result.stdout.strip())
|
||||
print(f"\n🎯 Total Coverage: {coverage_pct:.2f}%")
|
||||
|
||||
if coverage_pct >= 80:
|
||||
print("✅ Coverage target met (≥80%)")
|
||||
return True
|
||||
else:
|
||||
print("⚠️ Coverage below target (≥80%)")
|
||||
return False
|
||||
except ValueError:
|
||||
print("⚠️ Could not parse coverage percentage")
|
||||
|
||||
return success
|
||||
|
||||
|
||||
def main():
|
||||
"""Main coverage testing function."""
|
||||
print("=" * 60)
|
||||
print("🧪 Gallery Generator - Automated Coverage Testing")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
success = run_coverage_tests()
|
||||
|
||||
if success:
|
||||
print("\n✅ Coverage testing completed successfully!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\n❌ Coverage testing failed!")
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n💥 Coverage testing error: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user