diff --git a/tests/test_declare.py b/tests/test_declare.py index ff02684f7..e4311fa40 100644 --- a/tests/test_declare.py +++ b/tests/test_declare.py @@ -440,18 +440,24 @@ 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() @@ -459,9 +465,7 @@ def test_reads_off_the_round_face_and_matches_detection(self): ) 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). @@ -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) @@ -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" diff --git a/tests/test_issue_1143_hole_completeness.py b/tests/test_issue_1143_hole_completeness.py index 02b8d1fd8..6074e82bd 100644 --- a/tests/test_issue_1143_hole_completeness.py +++ b/tests/test_issue_1143_hole_completeness.py @@ -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"} diff --git a/tests/test_issue_1202_observed_drawing_consumer.py b/tests/test_issue_1202_observed_drawing_consumer.py index 6a4db343e..157d98024 100644 --- a/tests/test_issue_1202_observed_drawing_consumer.py +++ b/tests/test_issue_1202_observed_drawing_consumer.py @@ -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 @@ -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. @@ -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" diff --git a/tests/test_issue_1296_cylindrical_diameter_pmi.py b/tests/test_issue_1296_cylindrical_diameter_pmi.py index 649988110..6567143ab 100644 --- a/tests/test_issue_1296_cylindrical_diameter_pmi.py +++ b/tests/test_issue_1296_cylindrical_diameter_pmi.py @@ -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( diff --git a/tests/test_issue_1332_zone_labels.py b/tests/test_issue_1332_zone_labels.py deleted file mode 100644 index 348c7228c..000000000 --- a/tests/test_issue_1332_zone_labels.py +++ /dev/null @@ -1,70 +0,0 @@ -"""`--zones` must not disable the ink check (#1332, review round 5). - -The tightness gate used to compare a label box's shorter side against the -*sheet's own median*. `min(width, height)` on a one-character label is the glyph -**width**, not the text height, so `--zones` — a public CLI flag and `Sheet` -option — put 28 single-character zone labels on the sheet, dragged the median to -1.051 mm, and pushed the threshold below the ordinary 2.166 mm label height. -Every real label was then judged untight and the whole check reported nothing. - -Four findings became zero, silently, through a documented user-facing flag. This -pins the property that fixed it: the gate depends on the box alone. -""" - -from draftwright.linting.structural import lint_drawing - -_CODE = "annotation_ink_overlap" - - -class _Bounds: - 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 _Annotation: - """The small duck-typed surface read by ``lint_drawing``.""" - - def __init__(self, label, label_bbox, segments, full=None): - self.label = label - self.label_bbox = label_bbox - self.segments = segments - self._full = full or label_bbox - self.elbow = None - - def bounding_box(self): - return _Bounds(self._full) - - -def _crossing_pair(): - target = _Annotation("75.5", (10.0, 10.0, 20.0, 12.2), []) - crosser = _Annotation( - "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(): - # Narrow one-character boxes reproduce the population that used to lower the sheet-wide - # median below an ordinary label's text height. They are separated and carry no ink. - return [ - _Annotation(chr(65 + index % 26), (100 + 5 * index, 100, 101 + 5 * index, 102.2), []) - for index in range(28) - ] - - -def _crossings(annotations): - return sorted(issue.message for issue in lint_drawing(annotations) if issue.code == _CODE) - - -def test_the_fixture_actually_reports_a_crossing(): - assert _crossings(list(_crossing_pair())) - - -def test_zone_labels_do_not_change_the_findings(): - without_zones = _crossings(list(_crossing_pair())) - with_zones = _crossings([*_crossing_pair(), *_zone_labels()]) - assert with_zones == without_zones diff --git a/tests/test_issue_1460_step_inspection.py b/tests/test_issue_1460_step_inspection.py index 51622db66..d43d28a0a 100644 --- a/tests/test_issue_1460_step_inspection.py +++ b/tests/test_issue_1460_step_inspection.py @@ -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", diff --git a/tests/test_lint_ink_overlap.py b/tests/test_lint_ink_overlap.py index 75aa65b4e..6c3599fa1 100644 --- a/tests/test_lint_ink_overlap.py +++ b/tests/test_lint_ink_overlap.py @@ -28,6 +28,7 @@ shorter_side, warn_if_untight, ) +from draftwright.linting.structural import lint_drawing _LOGGER = "draftwright.linting.ink_overlap" @@ -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) @@ -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 diff --git a/tests/test_script_detail_parity.py b/tests/test_script_detail_parity.py index 80611a975..f47d67445 100644 --- a/tests/test_script_detail_parity.py +++ b/tests/test_script_detail_parity.py @@ -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", diff --git a/tests/test_solve_trace.py b/tests/test_solve_trace.py index 892a8b167..c074b3402 100644 --- a/tests/test_solve_trace.py +++ b/tests/test_solve_trace.py @@ -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}" @@ -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() diff --git a/tests/test_suite_shape.py b/tests/test_suite_shape.py index aa98a7532..2937a3453 100644 --- a/tests/test_suite_shape.py +++ b/tests/test_suite_shape.py @@ -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():