"""
Simple test in Blender background mode.
Just imports and starts server without the polling wrapper.
"""
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT / "python"))
print("[Test] Blender background test starting...", flush=True)
print(f"[Test] Python: {sys.executable}", flush=True)
# Check if bpy is available
try:
import bpy
print(f"[Test] bpy available: scene = {bpy.context.scene.name}", flush=True)
except ImportError:
print("[Test] bpy NOT available (not running in Blender)", flush=True)
bpy = None
# Test Rust module
print("[Test] Importing blender_mcp...", flush=True)
import blender_mcp
print(f"[Test] OK: {dir(blender_mcp)}", flush=True)
# Create and start server
print("[Test] Creating BlenderMcp...", flush=True)
mcp = blender_mcp.BlenderMcp("blender_test", 8765)
print(f"[Test] Created: tag={mcp.tag}, port={mcp.port}", flush=True)
print("[Test] Starting server...", flush=True)
port = mcp.start()
print(f"[Test] Server running on http://127.0.0.1:{port}/mcp", flush=True)
# Poll for any commands (none expected, just test the method)
cmd = mcp.poll()
print(f"[Test] poll() returned: {cmd}", flush=True)
# Stop
print("[Test] Stopping server...", flush=True)
mcp.stop()
print("[Test] Server stopped", flush=True)
print("[Test] SUCCESS - All tests passed!", flush=True)