85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Quick test demo showing the working test framework functionality
|
||
|
|
"""
|
||
|
|
import asyncio
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
|
||
|
|
# Add project root to path
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
|
||
|
|
from tests.test_client import test_clients
|
||
|
|
|
||
|
|
|
||
|
|
async def demo_test():
|
||
|
|
"""Demo of the testing framework functionality"""
|
||
|
|
print("🎮 City Builder - Test Framework Demo")
|
||
|
|
print("=" * 50)
|
||
|
|
|
||
|
|
# Test 1: Single client connection
|
||
|
|
print("\n✅ Test 1: Single client connection")
|
||
|
|
async with test_clients("demo_player") as [client]:
|
||
|
|
print(f" Connected: {client.connected}")
|
||
|
|
print(f" Player: {client.player_data['nickname']}")
|
||
|
|
print(f" Money: ${client.get_money():,}")
|
||
|
|
print(f" Population: {client.get_population()}")
|
||
|
|
|
||
|
|
# Test 2: Building placement
|
||
|
|
print("\n✅ Test 2: Building placement")
|
||
|
|
async with test_clients("builder") as [client]:
|
||
|
|
# Place a road
|
||
|
|
await client.place_building("road", 50, 50)
|
||
|
|
message = await client.receive_message(timeout=2.0)
|
||
|
|
if message and message["type"] == "building_placed":
|
||
|
|
print(f" Successfully placed: {message['building']['type']}")
|
||
|
|
print(f" At coordinates: ({message['building']['x']}, {message['building']['y']})")
|
||
|
|
else:
|
||
|
|
print(f" Error or unexpected message: {message}")
|
||
|
|
|
||
|
|
# Test 3: Chat functionality
|
||
|
|
print("\n✅ Test 3: Chat functionality")
|
||
|
|
async with test_clients("sender", "receiver") as [sender, receiver]:
|
||
|
|
# Clear any initial messages
|
||
|
|
receiver.clear_messages()
|
||
|
|
|
||
|
|
# Send chat message
|
||
|
|
test_message = "Hello from test framework!"
|
||
|
|
await sender.send_chat(test_message)
|
||
|
|
|
||
|
|
# Receive chat message
|
||
|
|
message = await receiver.receive_message(timeout=2.0)
|
||
|
|
if message and message["type"] == "chat":
|
||
|
|
print(f" Message sent: '{test_message}'")
|
||
|
|
print(f" Message received: '{message['message']}'")
|
||
|
|
print(f" From: {message['nickname']}")
|
||
|
|
else:
|
||
|
|
print(f" Error or unexpected message: {message}")
|
||
|
|
|
||
|
|
# Test 4: Multiple client interaction
|
||
|
|
print("\n✅ Test 4: Multiple client interaction")
|
||
|
|
async with test_clients("alice", "bob", "charlie") as [alice, bob, charlie]:
|
||
|
|
print(f" Connected clients: {len([alice, bob, charlie])}")
|
||
|
|
print(f" Alice: ${alice.get_money():,}")
|
||
|
|
print(f" Bob: ${bob.get_money():,}")
|
||
|
|
print(f" Charlie: ${charlie.get_money():,}")
|
||
|
|
|
||
|
|
# All clients send cursor movements simultaneously
|
||
|
|
await asyncio.gather(
|
||
|
|
alice.send_cursor_move(10, 20),
|
||
|
|
bob.send_cursor_move(30, 40),
|
||
|
|
charlie.send_cursor_move(50, 60)
|
||
|
|
)
|
||
|
|
print(" All cursor movements sent successfully")
|
||
|
|
|
||
|
|
print("\n🎉 Test framework demo completed!")
|
||
|
|
print("\n📊 Summary:")
|
||
|
|
print(" ✅ WebSocket connections work")
|
||
|
|
print(" ✅ Building placement works")
|
||
|
|
print(" ✅ Chat system works")
|
||
|
|
print(" ✅ Multiple clients work")
|
||
|
|
print(" ✅ Async operations work")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
asyncio.run(demo_test())
|