"""Tests for output format generators (SVG, DXF, JSON)."""
from __future__ import annotations
import json
import io
import ezdxf
import pytest
from pipeline.postprocess import PathInfo, PostProcessResult, postprocess_svg
from output.svg import generate_svg
from output.json_output import generate_json
from output.dxf import generate_dxf
def _read_dxf(dxf_bytes: bytes) -> ezdxf.document.Drawing:
"""Read DXF bytes back into an ezdxf document (needs StringIO, not BytesIO)."""
return ezdxf.read(io.StringIO(dxf_bytes.decode("utf-8")))
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
SIMPLE_SVG = (
'"
)
# SVG with an outer CCW rectangle and an inner CW rectangle (island/hole)
SVG_WITH_ISLAND = (
'"
)
# SVG with an open path (no Z close)
SVG_OPEN_PATH = (
'"
)
def _make_result(svg: str = SIMPLE_SVG, epsilon: float = 0.1) -> PostProcessResult:
"""Run postprocess pipeline and return result for testing output generators."""
return postprocess_svg(svg, epsilon=epsilon)
# ---------------------------------------------------------------------------
# SVG output tests
# ---------------------------------------------------------------------------
class TestSVGOutput:
def test_returns_string(self):
result = _make_result()
svg = generate_svg(result)
assert isinstance(svg, str)
def test_contains_svg_root(self):
result = _make_result()
svg = generate_svg(result)
assert "