Skip to content

test: pin that drawImage's cache survives a pygame restart - #51

Merged
dmccoystephenson merged 2 commits into
mainfrom
test/pin-draw-image-cache-survives-restart
Oct 16, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
test/pin-draw-image-cache-survives-restart

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle for drawImage's image cache.

  • Adds test_draw_image_cache_survives_a_pygame_restart. The comment in drawImage justifies skipping the font cache's display-session invalidation by saying that a surface from pygame.image.load survives a pygame.quit()/init() cycle ("verified empirically"). No test covered that claim, so a pygame upgrade that broke it would have gone unnoticed and the cache would blit stale surfaces. The new test draws an image, restarts pygame, rebinds the instance to the new display, and asserts:
    • the cached surfaces are reused (no reload, no rescale), and
    • they still draw correctly (pixel colors inside and outside the region).
  • This is a characterization test only. No production code was changed.

No tracking issue: the gap was found during triage.

Mutation check

A display-session invalidation was temporarily added to drawImage, so that the cache was dropped after the restart. The new test then failed (assert ([('…/red.bmp',)], …) == ([], [])). After graphik.py was restored, the test passed again.

Test plan

  • python3 -m py_compile src/main/python/preponderous/graphik/graphik.py
  • SDL_VIDEODRIVER=dummy python3 -m pytest: 62 passed (61 before)
  • The new test runs headless under the dummy SDL driver (via conftest.py)

Triage notes (deferred issues)

All four open issues were skipped this cycle because each needs a maintainer decision or a change to .github/workflows/, which is excluded from autonomous change:

A documentation sweep of README.md, RELEASING.md, pyproject.toml and the in-code docstrings found no drift beyond what those issues already track.

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

dmccoystephenson and others added 2 commits October 16, 2026 02:03
drawImage skips the font cache's display-session invalidation because
a loaded surface survives a pygame.quit()/init() cycle. Nothing tested
that claim, so this adds a test showing the cached surfaces are reused
and still draw correctly after a restart.

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

Copy link
Copy Markdown
Member Author

Self-review rubric (performed inline; no independent reviewer was available):

  • Scope: PASS. The only file touched is src/test/python/preponderous/graphik/test_graphik.py (one new test plus a comment fix).
  • Tests-new: PASS (n/a). No new public method was added.
  • Tests-fix: PASS (n/a, characterization). The mutation check is still recorded: with display-session invalidation temporarily added to drawImage, the test failed; with graphik.py restored, it passed.
  • Sibling structure: PASS. The test reuses the existing _make_graphik, _write_solid_image, _count_image_loads, _count_image_scales and _rgb helpers and sits with the other drawImage cache tests.
  • Sibling renames: PASS (n/a). Nothing was renamed.
  • Docs: PASS. No behavior changed, so README.md, RELEASING.md and the docstrings stay accurate.
  • Issue resolution: PASS (n/a). There is no Closes reference.
  • Manual validation: PASS. The Compile and test jobs are green on 3.9, 3.10, 3.11, 3.12 and 3.13, and locally pytest reports 62 passed.
  • camelCase / Backward-compat / No new deps: PASS. graphik.py was not modified.
  • Headless: PASS. The test runs under the dummy SDL driver set by conftest.py.

Findings:

  • src/test/python/preponderous/graphik/test_graphik.py:445: the original comment said that the test as a whole "fails" if the restart claim stops holding. That was imprecise, because the no-reload assertion would still pass in that case and only the pixel assertions would catch it. The comment was corrected in a follow-up commit.
  • Out-of-diff observation: the test rebinds the public gameDisplay attribute after the restart. Apex already uses that attribute, so relying on it in a test adds no new contract.

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 5663880 into main Oct 16, 2026
5 checks passed
@dmccoystephenson
dmccoystephenson deleted the test/pin-draw-image-cache-survives-restart branch October 16, 2026 08:06
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