-
Notifications
You must be signed in to change notification settings - Fork 988
Added Basic Visualization tests #2767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce a new visualization test suite for various Mesa agent-based models in a new test file. This suite uses Playwright and Solara to render and capture screenshots of visualizations before and after model progression, verifying that the visual output changes as expected. The test suite covers multiple example models, each with its own setup and portrayal logic. Additionally, the development dependencies in the Changes
Sequence Diagram(s)sequenceDiagram
participant Tester as pytest
participant Model as Mesa Model
participant Viz as SpaceMatplotlib/PlotMatplotlib
participant Solara as Solara Test Fixture
participant Browser as Playwright Page
Tester->>Model: Initialize with seed
Tester->>Viz: Create initial visualization
Viz->>Solara: Display visualization
Solara->>Browser: Render and capture screenshot
Tester->>Model: Step model N times
Tester->>Viz: Create updated visualization
Viz->>Solara: Display updated visualization
Solara->>Browser: Render and capture updated screenshot
Tester->>Tester: Compare screenshots (assert visual change)
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
tests/test_examples_viz.py (2)
63-70
: Potential memory-leak of Matplotlib figuresYou create two new
SpaceMatplotlib
and optionallyPlotMatplotlib
instances per test without closing the previous figures; after dozens of tests this can exhaust the Matplotlib figure manager and memory.Add an explicit
plt.close('all')
(or call the components’close()
method if they expose one) right after you finish the first screenshot and again after the second.
26-34
: Minor: defaultsteps=5
may hide bugs in slow-evolving modelsSome models (e.g. Conway’s with sparse seeds) need more than 5 steps for visible change. Consider exposing
steps
as a parameter in each test call so that individual tests can override the default when required.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pyproject.toml
(1 hunks)tests/test_examples_viz.py
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build (windows, 3.13)
🔇 Additional comments (2)
pyproject.toml (1)
66-69
: Add Playwright browser installation step & consider pinning versions
- Adding
playwright
todev
is necessary for the new screenshot tests, but the tests will still fail on fresh CI runners unless the browsers are installed (playwright install --with-deps
orpython -m playwright install
).
• Please ensure the CI pipeline (or a post-install hook) downloads the browsers or the tests will error with “Executable doesn’t exist”.- None of the three new dev dependencies is version-pinned while most of your runtime deps are. Un-pinned UI-automation libraries tend to ship breaking changes frequently; consider pinning to the latest known-good versions or adding an upper bound.
Would you like a small CI snippet showing how to cache & install the Playwright browsers?
tests/test_examples_viz.py (1)
90-97
: Base-64 inequality check can still be flaky on headless renderersAnti-aliasing, timestamps, or background metadata may change between runs even if the visual content is identical, giving false positives/negatives. If you encounter flakes later:
• Hash the image array after stripping metadata (e.g. via Pillow).
• Or compare perceptual hashes (e.g.imagehash.phash
) to tolerate pixel-level noise while still catching genuine changes.
Performance benchmarks:
|
Thanks a lot for this PR! @Corvince any chance you could review? |
Summary
Adds visualization tests for example models.
Motive
Part of #2741.
Implementation
Adds basic tests to confirm the data is passed onto the the plot components and space component is changing with step or not.
Additional Notes
Ran every test 15 times (total 135 times), found no flaky tests.

Summary by CodeRabbit
Tests
Chores