Skip to content

test: pin that a color's alpha is not blended by drawRectangle - #70

Merged
dmccoystephenson merged 1 commit into
mainfrom
test/pin-rectangle-color-alpha-not-blended
Nov 8, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
test/pin-rectangle-color-alpha-not-blended

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle with a matching documentation note. Current behavior is pinned; no production logic is changed.

  • An (r, g, b, a) fill color is never blended by drawRectangle (and therefore by drawButton's box), because pygame.draw writes colors directly:
    • on the display, the shape is painted opaquely whatever a is (even a = 0);
    • on a pygame.SRCALPHA surface, the color's alpha replaces the pixels' own alpha instead of blending over them.
  • Neither behavior was documented or tested. A consumer passing a 4-tuple expecting translucency gets an opaque box, or a "hole" punched in an off-screen alpha surface.
  • Added test_draw_rectangle_paints_a_translucent_color_opaquely_on_the_display (parametrized over a = 0 and a = 128) and test_draw_rectangle_overwrites_the_alpha_of_a_per_pixel_alpha_surface.
  • Documented the caveat in the drawRectangle color and drawButton colorBox docstrings, and in the README beside the color constants.

drawText's handling of an alpha component was deliberately left out of scope: it goes through Font.render, whose treatment of foreground alpha was not verified across the pygame versions CI installs, so pinning it here risked a version-dependent test.

Test plan

  • python3 -m py_compile src/main/python/preponderous/graphik/graphik.py
  • pytest — 151 passed (148 before + 3 new), pygame 2.1.2 locally
  • CI Test workflow green across 3.9–3.13 (current pygame), confirming the pygame.draw behavior holds on the newer version

Deferred issues

Every open issue was skipped this cycle because each is gated on a maintainer decision or on .github/workflows/, which is excluded from autonomous change: #68 (whole-float font size: choice among three options), #61 (fractional drawButton hit test: consumer-visible shift), #46, #39 and #34 (workflow files), #40 (namespace-package convention across sibling projects).

No tracking issue — gap found during triage.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

pygame.draw never blends, so an (r, g, b, a) fill paints opaquely on
the display and overwrites the pixel alpha of a per-pixel-alpha
surface. Pin both and document the caveat for drawRectangle and
drawButton's box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (anchored on the CI Test run and local pytest):

  • Scope: PASS — three files, all serving the one pinned behavior: the tests, the two affected docstrings (drawRectangle color, drawButton colorBox), and one README paragraph. No unrelated churn.
  • Tests-new: PASS — no new public method; three new test cases (one parametrized over a = 0 and a = 128, one per-pixel-alpha surface).
  • Tests-fix: N/A — no production logic changed; these are characterization tests of current behavior.
  • Sibling structure: PASS — new tests reuse _make_graphik / _rgb and sit beside the existing drawRectangle fill tests, with the same leading-comment style.
  • Sibling renames: N/A — nothing renamed.
  • Docs: PASS — README and both docstrings describe the pinned behavior; _version.py untouched, so no version drift is possible.
  • Issue resolution: N/A — no Closes; gap found during triage, recorded in the PR body.
  • Manual validation: PASS — py_compile OK; local pytest 151 passed on pygame 2.1.2; CI Compile and test green on 3.9, 3.10, 3.11, 3.12 and 3.13 with the current pygame, confirming the behavior holds across versions.
  • camelCase / Backward-compat / No new deps: PASS — no public member added, removed or changed; no new imports.
  • Headless: PASS — the tests run under the conftest dummy drivers and need no real display.

Findings flagged for judgment (no change applied):

  • src/main/python/preponderous/graphik/graphik.py — "on the display the rectangle is painted opaquely" is strictly true of any surface without per-pixel alpha, not only the display. The wording follows the README's framing, where the display is the common case; it could be generalized later if consumers draw onto plain off-screen surfaces.
  • The drawButton alpha claim is covered only transitively: its box is painted through drawRectangle, so no separate drawButton test was added.
  • src/test/python/preponderous/graphik/test_graphik.py — the per-pixel-alpha test calls pygame.display.init() although pygame.Surface does not need it. This was kept to match the off-screen sibling tests, and it does no harm.

This review was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 054728c into main Nov 8, 2026
5 checks passed
@dmccoystephenson
dmccoystephenson deleted the test/pin-rectangle-color-alpha-not-blended branch November 8, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant