PIWM / test_web_app.py
musictimer's picture
Fix initial bugs
02c6351
#!/usr/bin/env python3
"""
Test script to verify the web app can be imported and basic functionality works
"""
import logging
import sys
from pathlib import Path
# Add src to Python path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_imports():
"""Test if all required modules can be imported"""
logger.info("Testing imports...")
try:
# Test core modules
from config_web import web_config
logger.info("Web config imported")
from src.csgo.web_action_processing import WebCSGOAction
logger.info("Web action processing imported")
from src.game.web_play_env import WebPlayEnv
logger.info("Web play environment imported")
# Test web framework
import fastapi
import uvicorn
logger.info("Web framework imported")
# Test app
from app import app, WebGameEngine
logger.info("Main app imported")
return True
except Exception as e:
logger.error(f"Import failed: {e}")
return False
def test_config():
"""Test configuration setup"""
logger.info("Testing configuration...")
try:
from config_web import web_config
# Test path resolution
config_path = web_config.get_config_path()
logger.info(f"Config path: {config_path}")
spawn_dir = web_config.get_spawn_dir()
logger.info(f"Spawn directory: {spawn_dir}")
checkpoint_path = web_config.get_checkpoint_path()
logger.info(f"Checkpoint path: {checkpoint_path}")
return True
except Exception as e:
logger.error(f"Configuration test failed: {e}")
return False
def test_action_processing():
"""Test web action processing"""
logger.info("Testing action processing...")
try:
from src.csgo.web_action_processing import WebCSGOAction, web_keys_to_csgo_action_names
# Test key mapping
test_keys = {'KeyW', 'KeyA', 'Space'}
action_names = web_keys_to_csgo_action_names(test_keys)
logger.info(f"Key mapping: {test_keys} -> {action_names}")
# Test action creation
action = WebCSGOAction(
key_names=action_names,
mouse_x=10,
mouse_y=5,
l_click=False,
r_click=False
)
logger.info(f"Action created: {action}")
return True
except Exception as e:
logger.error(f"Action processing test failed: {e}")
return False
def main():
"""Run all tests"""
logger.info("Starting Diamond CSGO web app tests...")
tests = [
("Imports", test_imports),
("Configuration", test_config),
("Action Processing", test_action_processing),
]
passed = 0
total = len(tests)
for name, test_func in tests:
logger.info(f"\n--- Testing {name} ---")
if test_func():
logger.info(f"PASS: {name} test passed")
passed += 1
else:
logger.error(f"FAIL: {name} test failed")
logger.info(f"\n=== Test Results ===")
logger.info(f"Passed: {passed}/{total}")
if passed == total:
logger.info("All tests passed! The web app should work correctly.")
return True
else:
logger.error("Some tests failed. Please check the errors above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)