Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions tests/test_declare.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,28 +440,32 @@ def _filleted(radius=3):

return bd_fillet(Box(60, 40, 20).edges().filter_by(Axis.Z), radius)

@pytest.fixture(scope="class")
@classmethod
def rounded_drawing(cls):
solid = cls._filleted(3)
return solid, build_drawing(solid, number="X")

def test_explicit(self):
f = fillet(axis="z", radius=3, at=(28.5, 18.5, 0))
assert isinstance(f, FilletFeature)
assert f.axis == "z" and f.radius == 3 and f.frame.origin == pytest.approx((28.5, 18.5, 0))

def test_reads_off_the_round_face_and_matches_detection(self):
def test_reads_off_the_round_face_and_matches_detection(self, rounded_drawing):
# The object flavour reads the CYLINDRICAL blend face — radius off the cylinder, `at`
# on the round — and round-trips (in-plane) with the detected feature.
from OCP.BRepAdaptor import BRepAdaptor_Surface
from OCP.GeomAbs import GeomAbs_Cylinder

solid = self._filleted(3)
solid, dwg = rounded_drawing
face = next(
g
for g in solid.faces()
if BRepAdaptor_Surface(g.wrapped).GetType() == GeomAbs_Cylinder
)
f = fillet(face)
assert f.axis == "z" and abs(f.radius - 3) < 0.01
det = next(
x for x in build_drawing(solid, number="X").model().features if x.kind == "fillet"
)
det = next(x for x in dwg.model().features if x.kind == "fillet")
# Exact in-plane parity: declare reads the same on-round anchor the recogniser does — a
# point at mid angular/axial of the trimmed face (#622), not the off-surface bbox centre
# (the along-edge Z coord is view depth, so it need not match).
Expand Down Expand Up @@ -498,8 +502,8 @@ def test_anchor_lies_on_the_radius_surface_not_the_virtual_corner(self):
assert len(members) == 4
assert all(Vertex(*m.at).distance_to(grouped) < 0.05 for m in members)

def test_recognises_external_fillet(self):
dwg = build_drawing(self._filleted(3), number="X")
def test_recognises_external_fillet(self, rounded_drawing):
_, dwg = rounded_drawing
fs = [f for f in dwg.model().features if f.kind == "fillet"]
assert fs and all(abs(f.radius - 3) < 0.01 for f in fs)

Expand Down Expand Up @@ -540,9 +544,9 @@ def test_declared_fillet_renders_R_callout(self):
assert len(fs) == 1 and _fillet_label(fs[0].radius, 1) == "R3"
assert not any(i.severity == "error" for i in dwg.lint())

def test_equal_radii_group_as_n_times_R(self):
def test_equal_radii_group_as_n_times_R(self, rounded_drawing):
# #561 acceptance #2: repeated equal-radius fillets share one n× R callout.
dwg = build_drawing(self._filleted(3), number="X")
_, dwg = rounded_drawing
names = [n for n in dwg.annotations() if n.startswith("m_fillet")]
assert len(names) == 1 # ONE grouped callout, not four
assert dwg.get_annotation(names[0]).label == "4× R3"
Expand Down
11 changes: 10 additions & 1 deletion tests/test_issue_1143_hole_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -2490,12 +2490,21 @@ def test_unattached_external_countersink_false_positive_is_not_a_hole_requiremen
def test_failed_hole_table_escalation_restores_semantic_fallback_evidence(monkeypatch):
import draftwright.drawing as drawing_module

monkeypatch.setattr(drawing_module, "fit_box", lambda *_args, **_kwargs: None)
fit_attempts = []

def refuse_table_fit(*args, **kwargs):
fit_attempts.append((args, kwargs))
return None

monkeypatch.setattr(drawing_module, "fit_auxiliary_box", refuse_table_fit)
drawing = build_drawing(_dense_scattered_plate(), page="A3")

assert fit_attempts, "the table-fit seam was not exercised"
assert "hole_table_plan" not in drawing.annotations()
assert "table_dropped" in {issue.code for issue in drawing.lint()}
outcomes = _outcomes(drawing)
assert outcomes, "the failed table must leave hole requirements to assess"
assert any(item.state == "dropped" for item in outcomes)
assert not [item for item in outcomes if item.state == "missing"]
assert {item.state for item in outcomes} <= {"placed", "dropped"}

Expand Down
43 changes: 24 additions & 19 deletions tests/test_issue_1202_observed_drawing_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ def test_a_grouped_callout_accounts_for_every_member(self):
)


def _refuse_table_fit(monkeypatch):
from draftwright import drawing as drawing_module

attempts = []

def refuse(*args, **kwargs):
attempts.append((args, kwargs))
return None

monkeypatch.setattr(drawing_module, "fit_auxiliary_box", refuse)
return attempts


class TestAHoleTableIsAlsoTheFactReachingTheSheet:
"""Above ~16 scattered holes the engine WITHDRAWS the individual `hc_*` callouts and
places one table plus balloons. Reading only `hc_` scored every hole on such a sheet
Expand Down Expand Up @@ -279,7 +292,7 @@ def test_a_table_represented_hole_is_consumed_on_a_real_build(self):
f"a correct table-escalated sheet scored {sorted(set(outcomes))}"
)

def test_the_metric_is_not_inverted_on_dense_parts(self):
def test_the_metric_is_not_inverted_on_dense_parts(self, monkeypatch):
# The sharpest statement of the defect: a correct sheet must not score WORSE than
# the same part whose table failed to fit. Before the fix the correct sheet scored
# 16/16 unsupported and the broken one only 12/16.
Expand All @@ -288,36 +301,28 @@ def test_the_metric_is_not_inverted_on_dense_parts(self):
good_outcomes = _drawing_consumer_outcomes(good.recognition().holes, good)
good_lost = sum(1 for o in good_outcomes if o != "supported")

from draftwright import drawing as drawing_module

original = drawing_module.fit_box
drawing_module.fit_box = lambda *a, **k: None
try:
broken = build_drawing(part, page="A3")
broken_outcomes = _drawing_consumer_outcomes(broken.recognition().holes, broken)
finally:
drawing_module.fit_box = original
fit_attempts = _refuse_table_fit(monkeypatch)
broken = build_drawing(part, page="A3")
broken_outcomes = _drawing_consumer_outcomes(broken.recognition().holes, broken)
broken_lost = sum(1 for o in broken_outcomes if o != "supported")

assert fit_attempts, "the table-fit seam was not exercised"
assert "table_dropped" in {issue.code for issue in broken.lint()}
assert broken_lost > 0, "the table did not actually fail to fit; nothing is compared"
assert good_lost < broken_lost, (
f"the correct sheet lost {good_lost} holes and the broken one {broken_lost} — "
f"the metric rewards a worse drawing"
)

def test_a_dropped_table_is_not_credited(self):
def test_a_dropped_table_is_not_credited(self, monkeypatch):
# The ledger is written only after the table is placed and the balloon gate passes,
# and the annotation transaction rolls it back before that — so a `table_dropped`
# sheet must credit nothing. Asserted on the OUTCOME now that `_table_represented`
# is gone with the duplicate correspondence.
from draftwright import drawing as drawing_module

original = drawing_module.fit_box
drawing_module.fit_box = lambda *a, **k: None
try:
broken = build_drawing(self._dense(), page="A3")
finally:
drawing_module.fit_box = original
fit_attempts = _refuse_table_fit(monkeypatch)
broken = build_drawing(self._dense(), page="A3")
assert fit_attempts, "the table-fit seam was not exercised"
assert "table_dropped" in {issue.code for issue in broken.lint()}
names = {n for n, _o in broken.iter_annotations()}
assert not any(n.startswith("hole_table") for n in names), (
"the table reached the sheet after all; nothing is under test"
Expand Down
6 changes: 5 additions & 1 deletion tests/test_issue_1296_cylindrical_diameter_pmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,17 @@ def test_requirement_api_rejects_parameters_the_emitter_cannot_preserve():
hi=10,
at=(6, 5, 2.5),
)
with pytest.raises(ValueError, match="canonical imported diameter owner"):
with pytest.raises(ValueError) as caught:
slot.requirement(
4,
on="slot_width",
source="ap242_pmi",
source_ids=("dimension:unsupported",),
)
assert str(caught.value) == (
"requirement() supports only canonical imported step length or diameter "
"owners and the diameter owners of boss, hole, pattern, or rotational features"
)


@pytest.mark.parametrize(
Expand Down
70 changes: 0 additions & 70 deletions tests/test_issue_1332_zone_labels.py

This file was deleted.

4 changes: 4 additions & 0 deletions tests/test_issue_1460_step_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@
"draftwright.section_recess_contract", # pure validated pattern projection during detect
"draftwright.builder",
"draftwright.compose",
"draftwright.contract_values", # shared validation at the model boundary
"draftwright.inspection",
"draftwright.layout", # obligation priority during model planning
"draftwright.layout_scheme", # pure typed annotation-scheme validation
"draftwright.model.callout",
"draftwright.model.declare",
"draftwright.model.detect",
"draftwright.model.dimension_intent",
"draftwright.model.ir",
"draftwright.model.manufacturing_schedule",
"draftwright.model.planner",
"draftwright.pmi",
"draftwright.recogniser_policy",
Expand Down
57 changes: 57 additions & 0 deletions tests/test_lint_ink_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
shorter_side,
warn_if_untight,
)
from draftwright.linting.structural import lint_drawing

_LOGGER = "draftwright.linting.ink_overlap"

Expand Down Expand Up @@ -101,6 +102,25 @@ def __init__(self, segments, label="?"):
self.label = label


class _ZoneBounds:
def __init__(self, box):
self.min = type("P", (), {"X": box[0], "Y": box[1], "Z": 0.0})()
self.max = type("P", (), {"X": box[2], "Y": box[3], "Z": 0.0})()


class _ZoneAnnotation(_Annotation):
"""The duck-typed annotation surface used by the zone-label ink check."""

def __init__(self, label, label_bbox, segments, full=None):
super().__init__(segments, label)
self.label_bbox = label_bbox
self._full = full or label_bbox
self.elbow = None

def bounding_box(self):
return _ZoneBounds(self._full)


class TestLengthInside:
def test_a_segment_clean_through_the_box_measures_its_width(self):
assert length_inside(((0.0, 12.0), (30.0, 12.0)), BOX) == pytest.approx(10.0)
Expand Down Expand Up @@ -725,3 +745,40 @@ def test_the_same_box_still_reports_once(self):
warn_if_untight(box, seen, _DiagonalDim())
warn_if_untight(box, seen, _DiagonalDim())
assert len(records) == 1


def _zone_crossing_pair():
target = _ZoneAnnotation("75.5", (10.0, 10.0, 20.0, 12.2), [])
crosser = _ZoneAnnotation(
"35",
(30.0, 30.0, 35.0, 32.2),
[((0.0, 11.0), (40.0, 11.0))],
(0.0, 11.0, 40.0, 32.2),
)
return target, crosser


def _zone_labels():
# The narrow one-character boxes once lowered the sheet-wide median below a label's height.
return [
_ZoneAnnotation(chr(65 + index % 26), (100 + 5 * index, 100, 101 + 5 * index, 102.2), [])
for index in range(28)
]


def _zone_crossings(annotations):
return sorted(
issue.message
for issue in lint_drawing(annotations)
if issue.code == "annotation_ink_overlap"
)


def test_zone_label_fixture_reports_a_crossing_issue_1332():
assert _zone_crossings(list(_zone_crossing_pair()))


def test_zone_labels_preserve_crossing_findings_issue_1332():
without_zones = _zone_crossings(list(_zone_crossing_pair()))
with_zones = _zone_crossings([*_zone_crossing_pair(), *_zone_labels()])
assert with_zones == without_zones
2 changes: 1 addition & 1 deletion tests/test_script_detail_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_unplaceable_turned_head_reports_the_exact_step_lengths(monkeypatch):
def test_turned_head_redraw_drop_is_not_counted_again_as_request_failure(monkeypatch):
import draftwright.annotations.sections as sections

def failed_redraw(_drawing, _analysis, req, _view_name, _letter, *, ctx):
def failed_redraw(_drawing, _analysis, req, _view_name, _letter, *, ctx, reserved_box):
if req.kind == "turned-head":
ctx.record_issue(
"warning",
Expand Down
12 changes: 11 additions & 1 deletion tests/test_solve_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ def test_rejected_corrective_candidates_cannot_own_the_final_trace(self, monkeyp
import draftwright.builder as builder

writes = []
detected_model = SimpleNamespace(authored_dimensions=None)
detected_model = SimpleNamespace(
authored_dimensions=None,
requested_dimensions=(),
schedules=(),
features=(),
)

def fake_build(*_args, scale, **_kwargs):
label = "original" if scale is None else f"candidate:{scale:g}"
Expand All @@ -165,9 +170,14 @@ def fake_build(*_args, scale, **_kwargs):
page_w=297.0,
page_h=210.0,
views=("front", "detail_A"),
view_bounds=lambda _name: (10.0, 10.0, 40.0, 30.0),
items=(),
box_cache={},
solve_trace=recorder,
model=lambda: detected_model,
report=lambda: {"schema_version": 0},
lint=lambda **_kwargs: [],
annotation_scheme_decision={},
)
# Mirror _build_drawing_once: each speculative build writes the shared path.
recorder.write()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_suite_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
_TESTS = Path(__file__).resolve().parent

# Measured at fee4931 with `ls tests | grep -c '^test_issue'`. MAY ONLY SHRINK.
_MAX_ISSUE_MODULES = 151
_MAX_ISSUE_MODULES = 150


def test_unit_manifest_names_existing_test_modules_once():
Expand Down
Loading