Files
cdsl-cad/backend/tests/test_render_bundle.py

59 lines
1.8 KiB
Python

from __future__ import annotations
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "backend"))
from app.services.render_bundle import render_section # noqa: E402
from app.settings import ProviderConfig, ProviderModel, Settings # noqa: E402
BACKEND = ROOT / "backend"
def settings(root: Path) -> Settings:
provider = ProviderConfig("test", "Test", "https://example.invalid/v1", "test-key", (ProviderModel("test-model"),))
return Settings(
task_root=root / "tasks",
conversation_root=root / "conversations",
library_root=BACKEND / "cdsl_library",
engine_root=BACKEND / "engine" / "cdsl_engine",
llm_base_url=provider.base_url,
llm_api_key=provider.api_key,
llm_model="test-model",
llm_timeout_s=1,
default_provider_id="test",
providers=(provider,),
)
class RenderBundleTests(unittest.TestCase):
def test_section_uses_build123d_part_operation_and_emits_a_png(self) -> None:
import build123d as b3d
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
step_path = root / "block.step"
b3d.export_step(b3d.Box(20, 10, 8), str(step_path))
result = render_section(
settings(root),
step_path=step_path,
output_dir=root / "section",
origin_mm=[10, 5, 4],
normal=[1, 0, 0],
)
self.assertTrue(Path(str(result["path"])).is_file())
self.assertGreater(int(result["contour_count"]), 0)
self.assertEqual(result["renderer"], "python-occ-section-pillow")
if __name__ == "__main__":
unittest.main()