Skip to content

test: pin drawImage's preservation of per-pixel alpha - #44

Merged
dmccoystephenson merged 1 commit into
mainfrom
test/pin-draw-image-per-pixel-alpha
Sep 25, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
test/pin-draw-image-per-pixel-alpha

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • A characterization test is added for a behavior that drawImage's implementation comment promises but that no test pinned: convert_alpha() "preserves any per-pixel alpha" the loaded file carries, so a sprite's transparent pixels leave the display underneath visible.
  • The existing test_draw_image_converts_loaded_surface_for_faster_blits only asserts that the cached surface gained the SRCALPHA flag. A conversion that adds an alpha channel while discarding the file's own (e.g. convert().convert_alpha()) satisfies that check yet paints transparent sprite backgrounds opaque — a regression every consumer drawing sprites (Roam, Ophidian, etc.) would notice.
  • The fixture is a 32-bit BMP, which keeps its alpha channel without SDL_image, matching the portability rationale of the existing _write_solid_image helper.
  • No production code is changed. This is a Stage B (unit-test expansion) cycle.

Mutation check

Performed by editing graphik.py temporarily and restoring it afterwards:

drawImage load line ..._converts_loaded_surface... new test
convert_alpha() (current) PASS PASS
convert() FAIL FAIL
convert().convert_alpha() PASS FAIL

The last row is the gap this test closes.

Test plan

  • python3 -m py_compile src/main/python/preponderous/graphik/graphik.py
  • Import smoke test for preponderous.graphik.graphik
  • pytest (headless via conftest.py): 53 passed (pygame 2.1.2 / SDL 2.0.16, run locally)
  • Mutation check above

Deferred issues

All open issues were deferred because each one waits on a maintainer decision:

No tracking issue. The gap was found during a test-coverage sweep in 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

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

Copy link
Copy Markdown
Member Author

Self-review rubric (performed inline; not an independent review):

  • Scope: PASS — the diff touches only src/test/python/preponderous/graphik/test_graphik.py (+26 lines); no production code, docs, or version files are changed.
  • Tests-new: PASS (n/a) — no public method is added.
  • Tests-fix: PASS (n/a, no fix) — as a mutation check instead, graphik.py's load line was temporarily edited: convert().convert_alpha() fails only the new test (the existing SRCALPHA-flag test still passes), and convert() fails both. The source was restored and git status confirmed it unchanged.
  • Sibling structure: PASS — the test sits beside the other drawImage tests, reuses _make_graphik/_rgb, uses camelCase locals like its neighbours, and uses a BMP fixture as _write_solid_image does.
  • Sibling renames: PASS (n/a) — nothing is renamed.
  • Docs: PASS — the behavior pinned is already stated in drawImage's implementation comment; README, RELEASING.md and the docstrings need no change.
  • Issue resolution: PASS (n/a) — no Closes reference; a gap found during triage.
  • Manual validation: PASS — py_compile and the import smoke test succeed locally, and pytest ran 53 tests with 53 passing. The CI Test matrix (3.9–3.13) is green on the PR head.
  • camelCase / Backward-compat / Version sync / No new deps: PASS — no public surface, versions, or imports are changed.
  • Headless: PASS — the test runs under the conftest.py dummy SDL drivers, locally and in CI.

Judgment call: the BMP fixture relies on SDL keeping a 32-bit BMP's alpha channel on load. Both SDL 2.0.16 locally and the CI wheels do. A PNG would be the more realistic sprite format but needs SDL_image, so BMP was kept for consistency with the existing fixture's portability rationale.

Requesting Copilot as a reviewer failed (Could not resolve user with login 'copilot'), so this self-review serves as the review step.

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


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit f3b474a into main Sep 25, 2026
5 checks passed
@dmccoystephenson
dmccoystephenson deleted the test/pin-draw-image-per-pixel-alpha branch September 25, 2026 07:28
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