- Add complete pytest testing framework with conftest.py and test files - Add performance monitoring and benchmarking capabilities - Add plugin system with ccache plugin example - Add comprehensive documentation (API, deployment, testing, etc.) - Add Docker API wrapper for service deployment - Add advanced configuration examples - Remove old wget package file - Update core modules with enhanced functionality
259 lines
7.8 KiB
Python
Executable file
259 lines
7.8 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
Comprehensive test runner for deb-mock
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import argparse
|
|
import time
|
|
from pathlib import Path
|
|
|
|
|
|
def run_command(cmd, description, check=True):
|
|
"""Run a command and handle errors"""
|
|
print(f"\n🔄 {description}...")
|
|
print(f"Command: {' '.join(cmd)}")
|
|
|
|
start_time = time.time()
|
|
try:
|
|
result = subprocess.run(cmd, check=check, capture_output=True, text=True)
|
|
duration = time.time() - start_time
|
|
|
|
if result.returncode == 0:
|
|
print(f"✅ {description} completed successfully in {duration:.2f}s")
|
|
if result.stdout:
|
|
print("Output:", result.stdout)
|
|
else:
|
|
print(f"❌ {description} failed with return code {result.returncode}")
|
|
if result.stderr:
|
|
print("Error:", result.stderr)
|
|
if result.stdout:
|
|
print("Output:", result.stdout)
|
|
|
|
return result
|
|
except subprocess.CalledProcessError as e:
|
|
duration = time.time() - start_time
|
|
print(f"❌ {description} failed with exception in {duration:.2f}s")
|
|
print(f"Error: {e}")
|
|
if e.stdout:
|
|
print("Output:", e.stdout)
|
|
if e.stderr:
|
|
print("Error:", e.stderr)
|
|
return e
|
|
|
|
|
|
def install_test_dependencies():
|
|
"""Install test dependencies"""
|
|
cmd = [sys.executable, "-m", "pip", "install", "-r", "tests/requirements.txt"]
|
|
return run_command(cmd, "Installing test dependencies")
|
|
|
|
|
|
def run_unit_tests(parallel=False, coverage=True, verbose=False):
|
|
"""Run unit tests"""
|
|
cmd = [sys.executable, "-m", "pytest"]
|
|
|
|
if parallel:
|
|
cmd.extend(["-n", "auto"])
|
|
|
|
if coverage:
|
|
cmd.extend(["--cov=deb_mock", "--cov-report=term-missing"])
|
|
|
|
if verbose:
|
|
cmd.extend(["-v", "-s"])
|
|
|
|
cmd.append("tests/")
|
|
|
|
return run_command(cmd, "Running unit tests")
|
|
|
|
|
|
def run_integration_tests(parallel=False, coverage=True, verbose=False):
|
|
"""Run integration tests"""
|
|
cmd = [sys.executable, "-m", "pytest", "-m", "integration"]
|
|
|
|
if parallel:
|
|
cmd.extend(["-n", "auto"])
|
|
|
|
if coverage:
|
|
cmd.extend(["--cov=deb_mock", "--cov-report=term-missing"])
|
|
|
|
if verbose:
|
|
cmd.extend(["-v", "-s"])
|
|
|
|
cmd.append("tests/")
|
|
|
|
return run_command(cmd, "Running integration tests")
|
|
|
|
|
|
def run_performance_tests(parallel=False, coverage=True, verbose=False):
|
|
"""Run performance tests"""
|
|
cmd = [sys.executable, "-m", "pytest", "-m", "performance"]
|
|
|
|
if parallel:
|
|
cmd.extend(["-n", "auto"])
|
|
|
|
if coverage:
|
|
cmd.extend(["--cov=deb_mock", "--cov-report=term-missing"])
|
|
|
|
if verbose:
|
|
cmd.extend(["-v", "-s"])
|
|
|
|
cmd.append("tests/")
|
|
|
|
return run_command(cmd, "Running performance tests")
|
|
|
|
|
|
def run_plugin_tests(parallel=False, coverage=True, verbose=False):
|
|
"""Run plugin system tests"""
|
|
cmd = [sys.executable, "-m", "pytest", "-m", "plugin"]
|
|
|
|
if parallel:
|
|
cmd.extend(["-n", "auto"])
|
|
|
|
if coverage:
|
|
cmd.extend(["--cov=deb_mock", "--cov-report=term-missing"])
|
|
|
|
if coverage:
|
|
cmd.extend(["--cov=deb_mock", "--cov-report=term-missing"])
|
|
|
|
if verbose:
|
|
cmd.extend(["-v", "-s"])
|
|
|
|
cmd.append("tests/")
|
|
|
|
return run_command(cmd, "Running plugin system tests")
|
|
|
|
|
|
def run_all_tests(parallel=False, coverage=True, verbose=False):
|
|
"""Run all tests"""
|
|
cmd = [sys.executable, "-m", "pytest"]
|
|
|
|
if parallel:
|
|
cmd.extend(["-n", "auto"])
|
|
|
|
if coverage:
|
|
cmd.extend(["--cov=deb_mock", "--cov-report=term-missing", "--cov-report=html:htmlcov"])
|
|
|
|
if verbose:
|
|
cmd.extend(["-v", "-s"])
|
|
|
|
cmd.append("tests/")
|
|
|
|
return run_command(cmd, "Running all tests")
|
|
|
|
|
|
def generate_coverage_report():
|
|
"""Generate coverage report"""
|
|
cmd = [sys.executable, "-m", "coverage", "report"]
|
|
return run_command(cmd, "Generating coverage report")
|
|
|
|
|
|
def generate_html_coverage():
|
|
"""Generate HTML coverage report"""
|
|
cmd = [sys.executable, "-m", "coverage", "html"]
|
|
return run_command(cmd, "Generating HTML coverage report")
|
|
|
|
|
|
def run_linting():
|
|
"""Run code linting"""
|
|
# Check if flake8 is available
|
|
try:
|
|
cmd = [sys.executable, "-m", "flake8", "deb_mock/", "tests/"]
|
|
return run_command(cmd, "Running code linting")
|
|
except FileNotFoundError:
|
|
print("⚠️ flake8 not available, skipping linting")
|
|
return None
|
|
|
|
|
|
def run_type_checking():
|
|
"""Run type checking"""
|
|
# Check if mypy is available
|
|
try:
|
|
cmd = [sys.executable, "-m", "mypy", "deb_mock/"]
|
|
return run_command(cmd, "Running type checking")
|
|
except FileNotFoundError:
|
|
print("⚠️ mypy not available, skipping type checking")
|
|
return None
|
|
|
|
|
|
def run_security_scan():
|
|
"""Run security scanning"""
|
|
# Check if bandit is available
|
|
try:
|
|
cmd = [sys.executable, "-m", "bandit", "-r", "deb_mock/"]
|
|
return run_command(cmd, "Running security scan")
|
|
except FileNotFoundError:
|
|
print("⚠️ bandit not available, skipping security scan")
|
|
return None
|
|
|
|
|
|
def main():
|
|
"""Main test runner"""
|
|
parser = argparse.ArgumentParser(description="Comprehensive test runner for deb-mock")
|
|
parser.add_argument("--unit", action="store_true", help="Run unit tests only")
|
|
parser.add_argument("--integration", action="store_true", help="Run integration tests only")
|
|
parser.add_argument("--performance", action="store_true", help="Run performance tests only")
|
|
parser.add_argument("--plugin", action="store_true", help="Run plugin system tests only")
|
|
parser.add_argument("--all", action="store_true", help="Run all tests")
|
|
parser.add_argument("--parallel", action="store_true", help="Run tests in parallel")
|
|
parser.add_argument("--no-coverage", action="store_true", help="Disable coverage reporting")
|
|
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
|
|
parser.add_argument("--install-deps", action="store_true", help="Install test dependencies")
|
|
parser.add_argument("--lint", action="store_true", help="Run code linting")
|
|
parser.add_argument("--type-check", action="store_true", help="Run type checking")
|
|
parser.add_argument("--security", action="store_true", help="Run security scanning")
|
|
parser.add_argument("--coverage-report", action="store_true", help="Generate coverage report")
|
|
|
|
args = parser.parse_args()
|
|
|
|
print("🚀 deb-mock Test Runner")
|
|
print("=" * 50)
|
|
|
|
# Change to project directory
|
|
project_dir = Path(__file__).parent
|
|
os.chdir(project_dir)
|
|
print(f"Working directory: {os.getcwd()}")
|
|
|
|
# Install dependencies if requested
|
|
if args.install_deps:
|
|
install_test_dependencies()
|
|
|
|
# Set coverage flag
|
|
coverage = not args.no_coverage
|
|
|
|
# Run specific test types
|
|
if args.unit:
|
|
run_unit_tests(args.parallel, coverage, args.verbose)
|
|
elif args.integration:
|
|
run_integration_tests(args.parallel, coverage, args.verbose)
|
|
elif args.performance:
|
|
run_performance_tests(args.parallel, coverage, args.verbose)
|
|
elif args.plugin:
|
|
run_plugin_tests(args.parallel, coverage, args.verbose)
|
|
elif args.all:
|
|
run_all_tests(args.parallel, coverage, args.verbose)
|
|
else:
|
|
# Default: run all tests
|
|
run_all_tests(args.parallel, coverage, args.verbose)
|
|
|
|
# Run additional checks if requested
|
|
if args.lint:
|
|
run_linting()
|
|
|
|
if args.type_check:
|
|
run_type_checking()
|
|
|
|
if args.security:
|
|
run_security_scan()
|
|
|
|
if args.coverage_report:
|
|
generate_coverage_report()
|
|
generate_html_coverage()
|
|
|
|
print("\n🎉 Test runner completed!")
|
|
print("=" * 50)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|