Spaces:
Paused
Paused
File size: 4,509 Bytes
56c063a | 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | #!/usr/bin/env python3
"""
Comprehensive test runner for MCP AI Data Scientist system.
Provides different test execution modes and coverage reporting.
"""
import argparse
import subprocess
import sys
import os
from pathlib import Path
def run_command(cmd, description):
"""Run a command and handle errors."""
print(f"\n{'='*60}")
print(f"Running: {description}")
print(f"Command: {' '.join(cmd)}")
print(f"{'='*60}")
result = subprocess.run(cmd, capture_output=False)
if result.returncode != 0:
print(f"β {description} failed with exit code {result.returncode}")
return False
else:
print(f"β
{description} completed successfully")
return True
def main():
parser = argparse.ArgumentParser(description="Run MCP AI Data Scientist tests")
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("--security", action="store_true", help="Run security tests only")
parser.add_argument("--all", action="store_true", help="Run all tests (default)")
parser.add_argument("--coverage", action="store_true", help="Generate coverage report")
parser.add_argument("--html-report", action="store_true", help="Generate HTML coverage report")
parser.add_argument("--parallel", "-n", type=int, help="Run tests in parallel (number of workers)")
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
parser.add_argument("--fast", action="store_true", help="Skip slow tests")
args = parser.parse_args()
# Default to running all tests if no specific type is selected
if not any([args.unit, args.integration, args.performance, args.security]):
args.all = True
# Base pytest command
cmd = ["python", "-m", "pytest"]
# Add verbosity
if args.verbose:
cmd.extend(["-v", "-s"])
# Add parallel execution
if args.parallel:
cmd.extend(["-n", str(args.parallel)])
# Add coverage if requested
if args.coverage or args.html_report:
cmd.extend([
"--cov=mcp_servers",
"--cov=orchestrator",
"--cov=streamlit_app",
"--cov=shared",
"--cov-report=term-missing"
])
if args.html_report:
cmd.append("--cov-report=html:htmlcov")
# Skip slow tests if requested
if args.fast:
cmd.extend(["-m", "not slow"])
# Test selection
test_commands = []
if args.unit or args.all:
unit_cmd = cmd + ["-m", "unit", "tests/"]
test_commands.append((unit_cmd, "Unit Tests"))
if args.integration or args.all:
integration_cmd = cmd + ["-m", "integration", "tests/"]
test_commands.append((integration_cmd, "Integration Tests"))
if args.performance or args.all:
perf_cmd = cmd + ["-m", "performance", "tests/"]
test_commands.append((perf_cmd, "Performance Tests"))
if args.security or args.all:
security_cmd = cmd + ["-m", "security", "tests/"]
test_commands.append((security_cmd, "Security Tests"))
# If no specific test type and not all, run everything
if not test_commands and not args.all:
test_commands.append((cmd + ["tests/"], "All Tests"))
# Run tests
all_passed = True
for test_cmd, description in test_commands:
if not run_command(test_cmd, description):
all_passed = False
# Generate coverage report summary
if args.coverage or args.html_report:
print(f"\n{'='*60}")
print("Coverage Report Summary")
print(f"{'='*60}")
if args.html_report:
print("π HTML coverage report generated in: htmlcov/index.html")
# Run coverage report
subprocess.run(["python", "-m", "coverage", "report", "--show-missing"])
# Final summary
print(f"\n{'='*60}")
if all_passed:
print("π All tests passed successfully!")
sys.exit(0)
else:
print("β Some tests failed. Check the output above.")
sys.exit(1)
if __name__ == "__main__":
main() |