Skip to content

Characterize RenderWindow's event dispatch, clock and repeated close - #54

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/characterize-render-window-dispatch
Oct 30, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/characterize-render-window-dispatch

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

A Stage B (unit-test expansion) cycle on RenderWindow. Six characterization tests are added to tests/test_render_window.py, covering behaviour of render_window.py that no existing test asserted. No production code is changed.

  • should_continue() returns True when no events are pending.
  • Registered handlers are called in registration order, once for each event, with events taken in poll order.
  • Once a QUIT event is seen, the rest of the events in that poll are not passed to handlers (the loop returns early).
  • After a QUIT, later should_continue() calls return False without polling pygame.event.get() again, and Pygame is not shut down until close() is called.
  • A single pygame.time.Clock is created in __init__ and used by every tick().
  • Each close() call runs pygame.quit() again. This is what the docstring's "Calling this more than once is harmless" currently means: the call is repeated, not skipped.

No tracking issue: the gap was found during triage. The README's description of the test suite (which modules mock Pygame) still holds, since tests/test_render_window.py already mocked it, so no documentation change is needed.

Test plan

  • python -m py_compile main.py graphik.py __init__.py render_window.py headless_run.py usage_reporting.py trace_client.py runs without errors.
  • python -m unittest tests.test_render_window ran 16 tests and all passed (10 before this PR).
  • python -m unittest discover -s tests ran 156 tests and all passed (150 on main).
  • Mutation check: changing the return False in the QUIT branch of should_continue() to continue makes test_events_after_quit_in_the_same_poll_are_not_dispatched fail. With the source restored, it passes again.
  • The Tests workflow is green on this PR.

Deferred issues

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

Lock in that a QUIT event ends dispatch for the rest of its poll, that
handlers run in registration order for each event, that no further
polling happens once QUIT has been seen, that one Clock serves every
tick, and that each close() call shuts Pygame down again.

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

Copy link
Copy Markdown
Member Author

Self-review rubric (Stage B, characterization only):

  • Scope: PASS — git diff --name-only origin/main...HEAD lists only tests/test_render_window.py; no production file is touched.
  • Tests-new: PASS — no new public method is added; each of the six new tests covers a render_window.py behaviour no existing test asserted (empty poll, handler/event ordering, early return on QUIT, no re-poll after QUIT, single Clock, repeated close()).
  • Tests-fix: not applicable — no bug fix. Mutation check done instead: changing the QUIT branch's return False to continue makes test_events_after_quit_in_the_same_poll_are_not_dispatched fail, and it passes again once the source is restored.
  • Sibling structure: PASS — the new tests use the existing setUp patch of render_window.pygame, the same *_SENTINEL event types and the same arrange/act/assert layout as the tests around them.
  • Sibling renames: not applicable — nothing is renamed.
  • Docs: PASS — the README's test-suite paragraph already says the render_window.py tests mock Pygame, and that is still true. No documented behaviour changes.
  • Issue resolution: not applicable — no Closes, since the gap was found during triage.
  • Manual validation: PASS — locally, py_compile of all top-level modules succeeds and python -m unittest discover -s tests ran 156 tests, all OK. The Tests workflow passed on the PR head (run 41015336109). The live Viron anchor was not run (UNVERIFIED-not-applicable): no rendering or service-call code is changed.

Findings and judgment calls:

  • tests/test_render_window.py:65 — test_one_clock_is_created_and_reused_by_every_tick overlaps with the existing test_tick_delegates_to_clock. It is kept because only the new test pins that a single Clock is constructed. Folding the older test into it was not done, so that no existing assertion is removed in a characterization cycle.
  • tests/test_render_window.py:84 — test_closing_twice_quits_pygame_each_time pins that pygame.quit() runs again on every close(). The close() docstring's "harmless" depends on pygame.quit() being idempotent, not on any guard in RenderWindow. If a guard is added later, this test should be updated on purpose.
  • Out of diff: the README's RenderWindow section does not say that events queued after a QUIT in the same poll never reach handlers. That is a candidate for a later documentation sweep, not this PR.

Verdict: ready to merge.

This review 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 7c67313 into main Oct 30, 2026
1 check passed
@dmccoystephenson
dmccoystephenson deleted the feature/characterize-render-window-dispatch branch October 30, 2026 06:40
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