- 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>
85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
"""Tests for uasset parser."""
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from unreal_mcp.core.uasset_parser import (
|
|
UAssetParser,
|
|
UAssetParseError,
|
|
scan_content_folder,
|
|
)
|
|
|
|
|
|
def test_uasset_parser_get_asset_info() -> None:
|
|
"""Test getting asset info from path."""
|
|
# Test Blueprint
|
|
info = UAssetParser.get_asset_info_from_path(Path("Content/BP_Enemy.uasset"))
|
|
assert info["name"] == "BP_Enemy"
|
|
assert info["type"] == "Blueprint"
|
|
|
|
# Test Material
|
|
info = UAssetParser.get_asset_info_from_path(Path("Content/M_Wood.uasset"))
|
|
assert info["name"] == "M_Wood"
|
|
assert info["type"] == "Material"
|
|
|
|
# Test StaticMesh
|
|
info = UAssetParser.get_asset_info_from_path(Path("Content/SM_Chair.uasset"))
|
|
assert info["name"] == "SM_Chair"
|
|
assert info["type"] == "StaticMesh"
|
|
|
|
# Test Unknown
|
|
info = UAssetParser.get_asset_info_from_path(Path("Content/SomeAsset.uasset"))
|
|
assert info["name"] == "SomeAsset"
|
|
assert info["type"] == "Unknown"
|
|
|
|
|
|
def test_uasset_parser_file_not_found() -> None:
|
|
"""Test parser with non-existent file."""
|
|
parser = UAssetParser(Path("nonexistent.uasset"))
|
|
|
|
with pytest.raises(UAssetParseError, match="File not found"):
|
|
parser.parse()
|
|
|
|
|
|
def test_uasset_parser_invalid_file(tmp_path: Path) -> None:
|
|
"""Test parser with invalid file."""
|
|
invalid_file = tmp_path / "invalid.uasset"
|
|
invalid_file.write_bytes(b"not a valid uasset")
|
|
|
|
parser = UAssetParser(invalid_file)
|
|
|
|
with pytest.raises(UAssetParseError, match="Invalid magic number"):
|
|
parser.parse()
|
|
|
|
|
|
def test_uasset_parser_valid_header(tmp_path: Path) -> None:
|
|
"""Test parser with valid header."""
|
|
# Create a minimal valid .uasset file
|
|
valid_file = tmp_path / "BP_Test.uasset"
|
|
# Magic number + minimal header
|
|
valid_file.write_bytes(b"\xc1\x83\x2a\x9e" + b"\x00" * 100)
|
|
|
|
parser = UAssetParser(valid_file)
|
|
result = parser.parse()
|
|
|
|
assert result["success"] is True
|
|
assert "header" in result
|
|
assert result["header"]["magic"] == "0x9e2a83c1"
|
|
|
|
|
|
def test_scan_content_folder(sample_project_path: Path) -> None:
|
|
"""Test scanning content folder."""
|
|
content_path = sample_project_path / "Content"
|
|
assets = scan_content_folder(content_path)
|
|
|
|
assert len(assets) == 2
|
|
names = [a["name"] for a in assets]
|
|
assert "BP_Enemy" in names
|
|
assert "BP_Player" in names
|
|
|
|
|
|
def test_scan_content_folder_nonexistent(tmp_path: Path) -> None:
|
|
"""Test scanning non-existent folder."""
|
|
assets = scan_content_folder(tmp_path / "nonexistent")
|
|
assert assets == []
|