Skip to content

test(shape-render): cover is_hit_by_point and bounds branches - #2368

Merged
wkentaro merged 1 commit into
mainfrom
test/shape-render-hit-test
Aug 4, 2026
Merged

test(shape-render): cover is_hit_by_point and bounds branches#2368
wkentaro merged 1 commit into
mainfrom
test/shape-render-hit-test

Conversation

@wkentaro

Copy link
Copy Markdown
Owner

is_hit_by_point is the shape hit-test that canvas selection and hover depend on, yet it had no direct unit coverage despite five distinct branches (line/linestrip edge distance, points never-hit, point radius, mask pixel lookup with an out-of-bounds guard, and the polygon/rectangle path-containment fallback) — it was exercised only transitively through GUI e2e canvas tests. This adds focused unit tests for each branch plus bounds().

The two tests that reach the QPainterPath fallback are left unmarked (no @pytest.mark.gui / qapp): QPainterPath is a Qt value type whose contains() / boundingRect() run with no QApplication, confirmed by running them in isolation.

Test plan

  • uv run pytest tests/unit/widgets/_shape_render_test.py -q — 12 passed
  • uv run ruff check / ruff format --check / uv run ty check — clean

@wkentaro wkentaro self-assigned this Jul 19, 2026
@wkentaro

Copy link
Copy Markdown
Owner Author

This was generated by AI during PR processing.

Verdict: `recommend-merge`

Test-only PR adding coverage for `is_hit_by_point` and `bounds` in `_widgets/_shape_render.py`. Reviewed the diff against source: the tests exercise every branch of `is_hit_by_point` and their assertions match the implementation.

  • line/linestrip -> `nearest_edge_index` (incl. the phantom closing-edge case, asserting the fix(shape): ignore linestrip's unrendered closing edge in hit-testing #2307 fix stays fixed)
  • `points` -> never a body hit; `point` -> radius = `point_size / 2` = 4px; empty point guarded to a miss
  • `mask` -> translated pixel read with an out-of-bounds guard
  • polygon -> path containment; `bounds` -> bounding rect extent

Branch is rebased onto current `main` and CI is green across all 11 configs (lint + 3 OS x Python 3.12/3.13/3.14). No rebase or push needed this tick. Test-only, so no runtime smoke to verify.

@wkentaro wkentaro added the recommend-merge pr: Agent finalized and endorses it: review and merge label Jul 19, 2026
@wkentaro
wkentaro force-pushed the test/shape-render-hit-test branch from fa5a27b to c78c39d Compare August 4, 2026 04:56
@wkentaro wkentaro added this to the next milestone Aug 4, 2026
Add unit tests for the shape hit-test used by canvas selection and
hover. is_hit_by_point had no direct unit coverage despite five distinct
branches (line/linestrip edge distance, points never-hit, point radius,
mask pixel lookup with out-of-bounds guard, and the polygon/rectangle
path-containment fallback), exercised only transitively through GUI
e2e tests.
@wkentaro
wkentaro force-pushed the test/shape-render-hit-test branch from c78c39d to b135137 Compare August 4, 2026 06:37
@wkentaro
wkentaro merged commit 96dd57c into main Aug 4, 2026
12 checks passed
@wkentaro
wkentaro deleted the test/shape-render-hit-test branch August 4, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

recommend-merge pr: Agent finalized and endorses it: review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant