#!/usr/bin/env python3 """ Test runner script for City Builder game tests. This script helps run tests with proper server setup. """ import sys import subprocess import time import socket from pathlib import Path def check_server_running(): """Check if the game server is running on the expected port.""" try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(2) result = sock.connect_ex(('127.0.0.1', 9901)) sock.close() return result == 0 except Exception: return False def run_tests(test_args=None): """Run the test suite with pytest.""" if not check_server_running(): print("โš ๏ธ Game server is not running on http://127.0.0.1:9901") print() print("Please start the server first:") print(" python run.py") print() print("Then run tests in another terminal:") print(" python run_tests.py") print(" # or directly:") print(" pytest") return False print("โœ… Game server is running") print("๐Ÿงช Running tests...") print() # Build pytest command cmd = [sys.executable, "-m", "pytest"] if test_args: cmd.extend(test_args) else: # Default: run all tests with verbose output cmd.extend(["-v"]) # Run tests result = subprocess.run(cmd) return result.returncode == 0 def main(): print("=" * 60) print("City Builder - Test Runner") print("=" * 60) print() # Pass any command line arguments to pytest test_args = sys.argv[1:] if len(sys.argv) > 1 else None success = run_tests(test_args) if success: print() print("โœ… All tests passed!") else: print() print("โŒ Some tests failed. Check output above.") return 1 return 0 if __name__ == "__main__": sys.exit(main())