Spaces:
Paused
Paused
Download scripts/run_tests.py from VAH6002/ai_data_scientist: direct link, hf CLI and curl.
- Browser
- Download file 4.51 kB
-
https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/scripts/run_tests.py
- Command line
-
hf download hf://spaces/VAH6002/ai_data_scientist/scripts/run_tests.py
-
curl -L -o run_tests.py https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/scripts/run_tests.py
4.51 kB
| #!/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() |