import pytest
from tests.integration.conftest import send_command
def test_real_mesh_stats_cube(real_blender_connection):
"""
Test mesh_stats on a real cube created in Blender.
"""
# 1. Clear scene (optional, but good practice)
# For now, we assume a fresh session or just add to it
# 2. Create a cube
create_code = "bpy.ops.mesh.primitive_cube_add(size=2)"
send_command(real_blender_connection, "execute_code", {"code": create_code})
# 3. Get stats
response = send_command(real_blender_connection, "mesh_stats", {"active_only": True})
assert response["status"] == "success"
result = response["result"]["stats"]
print(f"Mesh Stats Result: {result}")
# 4. Verify REAL geometry data
# A default cube has 8 vertices, 12 edges, 6 faces
assert result["vertex_count"] == 8
assert result["edge_count"] == 12
assert result["face_count"] == 6
# Verify face types (all quads)
assert result["quad_count"] == 6
assert result["tri_count"] == 0
assert result["ngon_count"] == 0
# Verify topology issues (should be clean)
assert result["non_manifold_edge_count"] == 0
def test_real_topology_issues_non_manifold(real_blender_connection):
"""
Test detection of non-manifold geometry.
"""
# 1. Create a cube
send_command(real_blender_connection, "execute_code", {"code": "bpy.ops.mesh.primitive_cube_add()"})
# 2. Make it non-manifold by deleting a face
# We need to select a face and delete it
make_non_manifold_code = """
import bpy
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
obj = bpy.context.active_object
obj.data.polygons[0].select = True
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.delete(type='FACE')
bpy.ops.object.mode_set(mode='OBJECT')
"""
send_command(real_blender_connection, "execute_code", {"code": make_non_manifold_code})
# 3. Detect issues
response = send_command(real_blender_connection, "detect_topology_issues", {})
assert response["status"] == "success"
result = response["result"]
print(f"Topology Issues Result: {result}")
# 4. Verify issues found
# Removing a face from a cube creates open edges (non-manifold)
assert result["total_issues_count"] > 0
issues = result.get("issues", [])
non_manifold_issue = next((i for i in issues if i["type"] == "non_manifold_edges"), None)
assert non_manifold_issue is not None
assert non_manifold_issue["count"] > 0