Unreal-mcp/tests/conftest.py
StillHammer ee2092dada Implement complete Python MCP server with 12 tools and blueprint-workflow skill
- Add MCP server with real Unreal Remote Execution Protocol (UDP 6766 + TCP 6776)
- Implement 12 MCP tools: project intelligence, scene manipulation, debug/profiling, blueprint ops
- Add enhanced .uasset parser with UE4/UE5 support
- Create /blueprint-workflow skill (analyze, bp-to-cpp, cpp-to-bp, transform, optimize)
- Include 21 passing tests
- Add complete user documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 18:59:43 +07:00

89 lines
2.7 KiB
Python

"""Pytest fixtures for Unreal MCP Server tests."""
import pytest
from pathlib import Path
from unittest.mock import MagicMock, AsyncMock
from unreal_mcp.core.unreal_connection import UnrealConnection
@pytest.fixture
def mock_connection() -> MagicMock:
"""Create a mock UnrealConnection for testing."""
conn = MagicMock(spec=UnrealConnection)
conn.is_connected = False
conn.connect.return_value = False
conn.execute = AsyncMock(return_value={"success": False, "error": "Not connected"})
conn.get_project_content_path.return_value = None
conn.get_project_source_path.return_value = None
return conn
@pytest.fixture
def connected_mock_connection() -> MagicMock:
"""Create a mock UnrealConnection that simulates being connected."""
conn = MagicMock(spec=UnrealConnection)
conn.is_connected = True
conn.connect.return_value = True
conn.execute = AsyncMock(return_value={"success": True, "data": {}})
conn.get_project_content_path.return_value = None
conn.get_project_source_path.return_value = None
return conn
@pytest.fixture
def sample_project_path(tmp_path: Path) -> Path:
"""Create a sample Unreal project structure for testing."""
project_path = tmp_path / "TestProject"
project_path.mkdir()
# Create Content folder with sample assets
content_path = project_path / "Content"
content_path.mkdir()
blueprints_path = content_path / "Blueprints"
blueprints_path.mkdir()
# Create dummy .uasset files
(blueprints_path / "BP_Enemy.uasset").write_bytes(b"\xc1\x83\x2a\x9e" + b"\x00" * 100)
(blueprints_path / "BP_Player.uasset").write_bytes(b"\xc1\x83\x2a\x9e" + b"\x00" * 100)
# Create Source folder with sample C++ files
source_path = project_path / "Source" / "TestProject"
source_path.mkdir(parents=True)
(source_path / "TestActor.h").write_text("""
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TestActor.generated.h"
UCLASS(Blueprintable)
class TESTPROJECT_API ATestActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float Health = 100.0f;
UFUNCTION(BlueprintCallable)
void TakeDamage(float Amount);
};
""")
return project_path
@pytest.fixture
def mock_connection_with_project(
mock_connection: MagicMock,
sample_project_path: Path,
) -> MagicMock:
"""Create a mock connection with a sample project path."""
mock_connection.project_path = sample_project_path
mock_connection.get_project_content_path.return_value = sample_project_path / "Content"
mock_connection.get_project_source_path.return_value = sample_project_path / "Source"
return mock_connection