#!/usr/bin/env python3 # Test runner for players refactor modules import sys import os import subprocess import argparse def run_tests(module=None, coverage=False, fast=False): """Run tests for the players refactor.""" # Base command cmd = [sys.executable, "-m", "pytest"] # Add test directory test_dir = os.path.join(os.path.dirname(__file__)) cmd.append(test_dir) # Module-specific test if module: test_file = f"test_{module}.py" test_path = os.path.join(test_dir, test_file) if os.path.exists(test_path): cmd = [sys.executable, "-m", "pytest", test_path] else: print(f"Test file {test_file} not found!") return False # Fast tests (exclude slow/integration tests) if fast: cmd.extend(["-m", "not slow and not integration"]) # Coverage reporting if coverage: cmd.extend([ "--cov=cogs.players", "--cov-report=term-missing", "--cov-report=html:htmlcov" ]) # Verbose output cmd.extend(["-v", "--tb=short"]) print(f"Running command: {' '.join(cmd)}") try: result = subprocess.run(cmd, cwd=os.path.dirname(os.path.dirname(__file__))) return result.returncode == 0 except Exception as e: print(f"Error running tests: {e}") return False def main(): parser = argparse.ArgumentParser(description="Run players refactor tests") parser.add_argument("command", nargs="?", default="all", choices=["all", "fast", "coverage", "player_lookup", "team_management", "paperdex", "standings_records", "gauntlet", "utility_commands"], help="Test command to run") parser.add_argument("--module", help="Specific module to test") args = parser.parse_args() if args.command == "all": success = run_tests() elif args.command == "fast": success = run_tests(fast=True) elif args.command == "coverage": success = run_tests(coverage=True) elif args.command in ["player_lookup", "team_management", "paperdex", "standings_records", "gauntlet", "utility_commands"]: success = run_tests(module=args.command) elif args.module: success = run_tests(module=args.module) else: success = run_tests() sys.exit(0 if success else 1) if __name__ == "__main__": main()