fix(com): create linear dimensions with AddDimRotated (#3)

dimension_linear always failed with '<unknown>.AddDimLinear' on the COM
backend — pywin32's dynamic dispatch error for a method that does not
exist: the AutoCAD ActiveX API has no AddDimLinear. AddDimRotated takes
the same arguments (XLine1Point, XLine2Point, DimLineLocation,
RotationAngle), so the call site only changes the method name.

Adds a mocked regression test asserting AddDimRotated is called with
the exact point/rotation arguments and AddDimLinear never is.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Umutcan Edizsalan
2026-07-14 00:01:53 +03:00
co-authored by Claude Fable 5
parent d0dfa8cf2d
commit 3a0519724b
3 changed files with 43 additions and 1 deletions
+36
View File
@@ -211,6 +211,42 @@ def test_safe_send_command_new_handle_detection():
assert set(result) == {"1C", "1D"}
# ---------------------------------------------------------------------------
# dimension_linear — must use AddDimRotated (GH issue #3)
# ---------------------------------------------------------------------------
@pytest.mark.asyncio
async def test_dimension_linear_uses_add_dim_rotated():
"""Regression for GH issue #3: the AutoCAD ActiveX API has no AddDimLinear
method — calling it raised ``<unknown>.AddDimLinear``. Linear dimensions
must go through AddDimRotated."""
backend = ComBackend()
async def _run_inline(func, *args, **kwargs):
return func(*args, **kwargs)
backend._run = _run_inline # bypass the COM executor thread
mspace = MagicMock()
with (
patch("backends.com_backend._msp", return_value=mspace),
patch("backends.com_backend._apoint", side_effect=lambda *a: tuple(float(v) for v in a)),
patch("backends.com_backend._regen"),
patch("backends.com_backend._apply_dim_tolerance"),
patch("backends.com_backend._entity_info", side_effect=lambda e: e),
):
await backend.dimension_linear(0, 0, 100, 0, 50, 20, rotation=0.0)
mspace.AddDimRotated.assert_called_once()
mspace.AddDimLinear.assert_not_called()
args = mspace.AddDimRotated.call_args[0]
assert args[0] == (0.0, 0.0) # ext line 1 origin
assert args[1] == (100.0, 0.0) # ext line 2 origin
assert args[2] == (50.0, 20.0) # dim line location
assert args[3] == pytest.approx(0.0) # rotation in radians
# ---------------------------------------------------------------------------
# Live integration — skipped unless AutoCAD is reachable
# ---------------------------------------------------------------------------