import os
import pytest
from app.processing import create_layered_curves_dxf
# Create a dedicated directory for test outputs
TEST_OUTPUT_DIR = "test_outputs"
os.makedirs(TEST_OUTPUT_DIR, exist_ok=True)
import trimesh
@pytest.fixture
def create_dummy_mesh_file(tmp_path):
"""
Creates a simple, valid mesh file for testing using trimesh.
Returns the path to the file.
"""
# Create a simple box primitive using trimesh
mesh = trimesh.creation.box()
file_path = tmp_path / "dummy_box.stl"
# Export the mesh to a file
mesh.export(file_path)
return str(file_path)
def test_processing_function_runs_and_creates_output(create_dummy_mesh_file):
"""
Tests that the core DXF generation function runs without errors and
produces a non-empty output file.
"""
input_file = create_dummy_mesh_file
output_file = os.path.join(TEST_OUTPUT_DIR, "output.dxf")
# The function is a generator, so we consume it to run it.
# We wrap it in list() to execute all the yields.
try:
# We need to iterate through the generator to make it execute
for _ in create_layered_curves_dxf(input_file, output_file):
pass
except Exception as e:
pytest.fail(f"Processing function raised an unexpected exception: {e}")
# Check that the output file was created and is not empty
assert os.path.exists(output_file), "Output file was not created."
assert os.path.getsize(output_file) > 0, "Output file is empty."