Spaces:
Sleeping
Sleeping
File size: 3,682 Bytes
02c6351 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#!/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)
|