tests: consolidate Solara viz tests and restore Altair coverage #2993#3011
tests: consolidate Solara viz tests and restore Altair coverage #2993#3011
Conversation
|
Performance benchmarks:
|
|
@coderabbitai review |
|
Tip For best results, initiate chat on the files or code changes. @DipayanDasgupta: Hello! How can I assist you with this pull request? Would you like me to:
Please let me know what you need! |
✅ Actions performedReview triggered.
|
WalkthroughThe pull request consolidates Solara visualization test coverage by adding modern Altair backend support testing to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/visualization/test_solara_viz_legacy.py (1)
15-20: Consider adding agents to validate portrayal rendering.The MockModel creates a grid but doesn't place any agents. This means the
agent_portrayalfunction won't actually be exercised during rendering, making the test less thorough in validating legacy dictionary-based portrayal behavior.🔎 Suggested enhancement to add agent validation
class MockModel(mesa.Model): def __init__(self): super().__init__() self.grid = MultiGrid(10, 10, True) + # Create and place an agent to exercise the portrayal function + agent = mesa.Agent(self) + self.grid.place_agent(agent, (5, 5))tests/visualization/test_solara_viz.py (1)
217-235: Test successfully addresses Altair coverage gap; consider enhanced validation.The test correctly demonstrates SpaceRenderer with Altair backend support using modern APIs (AgentPortrayalStyle). It fulfills the PR objective of restoring Altair coverage identified in issue #2993.
💡 Optional: Enhance test validation
Consider adding verification that the renderer actually produced output and that the portrayal function was exercised:
def test_modern_renderer_altair_support(): """Verify SpaceRenderer with Altair and AgentPortrayalStyle (Fixes #2993 coverage).""" class MockModel(mesa.Model): def __init__(self): super().__init__() self.grid = MultiGrid(10, 10, True) self.grid.place_agent(mesa.Agent(self), (5, 5)) model = MockModel() portrayal_called = False def portrayal(agent): nonlocal portrayal_called portrayal_called = True return AgentPortrayalStyle(marker="o", color="red") # This tests the new architecture with the Altair backend renderer = SpaceRenderer(model, backend="altair").setup_agents(portrayal).render() solara.render(SolaraViz(model, renderer)) assert renderer.backend == "altair" assert portrayal_called, "Portrayal function should have been called during rendering" assert renderer.agent_mesh is not None, "Agent mesh should be created after render"This validates that the rendering pipeline actually executed the portrayal logic.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tests/visualization/test_solara_viz.pytests/visualization/test_solara_viz_legacy.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/visualization/test_solara_viz_legacy.py (6)
mesa/space.py (1)
MultiGrid(1013-1086)mesa/visualization/solara_viz.py (1)
SolaraViz(58-221)mesa/visualization/components/altair_components.py (1)
make_altair_space(27-61)mesa/visualization/components/matplotlib_components.py (1)
make_mpl_space_component(25-60)mesa/model.py (1)
Model(30-255)mesa/visualization/space_renderer.py (1)
render(381-409)
🪛 Ruff (0.14.10)
tests/visualization/test_solara_viz_legacy.py
22-22: Unused function argument: agent
(ARG001)
tests/visualization/test_solara_viz.py
228-228: Unused function argument: agent
(ARG001)
🔇 Additional comments (2)
tests/visualization/test_solara_viz_legacy.py (1)
1-11: LGTM! Imports are appropriate for legacy visualization testing.The imports correctly include the legacy component makers (
make_mpl_space_componentandmake_altair_space) alongside the core visualization infrastructure.tests/visualization/test_solara_viz.py (1)
25-25: LGTM! Import correctly supports the new Altair backend test.The
SpaceRendererimport is appropriately added to enable testing of the modern renderer API with Altair support, addressing the coverage gap identified in issue #2993.
50e61b3 to
963f177
Compare
|
@ShreyasN707 @Nithin9585 Good catch! I have just pushed an update that explicitly removes test_solara_viz_updated.py. |
2dc9a6a to
0debdd6
Compare
|
I have updated PR #3011. It consolidates the tests into tests/visualization/ (aligned with #2994) but surpasses other solutions by using Pytest Parameterization to ensure 100% parity between Matplotlib and Altair. This ensures that any logic verified for one backend is automatically verified for the other, preventing future coverage gaps. |
24d4784 to
ad94d3d
Compare
ad94d3d to
2667f05
Compare
|
Thanks for this effort. @Nithin9585 @codebyNJ @ShreyasN707 please review using the "review" tab on this PR. @DipayanDasgupta can you update the PR description and format it properly? |
There was a problem hiding this comment.
@DipayanDasgupta The consolidation looks good and the modern vs legacy split is nice and clear now.
I only noticed a couple of small, non-blocking nits:
-
There are a few leftover # CodeRabbit Rec: comments in test_solara_viz_legacy.py that look like AI artifacts and could be cleaned up.
-
(Optional) In the backend parity test, using spy.call_count >= 1 would be a slightly more robust check than spy.called, though the current assertion is fine.
|
@EwoutH I have updated the PR description with proper formatting and structure. @ShreyasN707 Thanks for the review! I have pushed a fix to remove the leftover AI comments from the legacy file. Regarding the assertion, I stuck with |
|
@EwoutH could you give the final review , and let me know if the PR is ready for merging? |
EwoutH
left a comment
There was a problem hiding this comment.
I think this looks good, thanks!
@Sahil-Chhoker could you double check, especially if everything is covered now?
b730d06 to
046aa34
Compare
|
@Sahil-Chhoker Thanks for the detailed review! I've updated the PR to address both points:
This ensures the modern test file is focused purely on the new architecture and covers the property layer rendering logic. |
046aa34 to
1110bc2
Compare
Are these tests still relevant? If so, shouldn't it be moved to the legacy one? |
- Remove test_call_space_drawer from test_solara_viz.py (modern API only) - Move test_call_space_drawer to test_solara_viz_legacy.py - Preserves coverage of make_mpl_space_component/make_altair_space APIs - Modern file: 12 tests (SpaceRenderer only) - Legacy file: 2 tests (backwards compatibility) Addresses feedback from @Sahil-Chhoker and @EwoutH in mesa#3011
|
@EwoutH You're right they are relevent, I was in a bit of a rush , so I kind of overlooked that. I've restored the test_call_space_drawer logic and moved it into test_solara_viz_legacy.py. This ensures we keep coverage for make_mpl_space_component and other legacy APIs without cluttering the modern test file. All 14 tests are passing locally. |
- Remove test_call_space_drawer (tests old make_mpl_space_component API) - Add VoronoiGrid import to fix test_voronoi_grid_renderer - Keep PropertyLayer coverage in test_solara_viz_backends per review - All 12 tests passing with modern SpaceRenderer API only Addresses feedback from @Sahil-Chhoker in mesa#3011
|
@DipayanDasgupta Thanks for incorporating the review and sorry I won't be able to find time today but will look at it as soon as tomorrow. |
04a44cf to
2bd06d3
Compare
|
Hi @Sahil-Chhoker, thank you for the detailed and helpful review! I've pushed an update that incorporates all of your feedback. The changes include:
The tests are passing locally. Let me know if there is anything else |
Sahil-Chhoker
left a comment
There was a problem hiding this comment.
Good work, just a little cleanup.
2bd06d3 to
9e429de
Compare
Sahil-Chhoker
left a comment
There was a problem hiding this comment.
Good Work, LGTM, @EwoutH do you have anything to add before merging this PR?
|
@EwoutH @Sahil-Chhoker Any Updates? |
|
I’m good, @DipayanDasgupta thanks for the PR and @Sahil-Chhoker thanks for the extensive review! |




Summary
This PR refactors the Solara visualization tests into a modern/legacy structure, restores missing test coverage for the Altair backend, and improves the overall robustness of the test suite based on reviewer feedback. It removes redundant files and ensures both Matplotlib and Altair backends have feature parity in their testing.
Bug / Issue
Fixes #2993
Problem
A recent test reorganization inadvertently removed test coverage for Altair's
AgentPortrayalStylesupport.Duplicate and outdated test files (
test_solara_viz_updated.py) created ambiguity and maintenance overhead.The legacy and modern testing APIs were mixed, making the test suite harder to navigate and maintain.
Implementation
Structural Alignment: Migrated all visualization tests to the new
tests/visualization/directory, aligning with the project's goal to mirror the source module structure (#2994).Backend Parity: Implemented
@pytest.mark.parametrizeintest_solara_viz.pyto test both Matplotlib and Altair backends against the same modernSpaceRendererlogic, ensuring 100% parity and preventing future coverage gaps.Restored Coverage & Robustness: Based on reviewer feedback, the tests were significantly improved:
Assertions are now more robust, using
spy_*.assert_called_with(renderer)to verify that the correct objects are being passed to draw functions.Added specific
isinstancechecks to confirm that the correct backend renderer class (MatplotlibBackendorAltairBackend) is instantiated.Added negative test cases to confirm nothing is drawn when a renderer is not provided.
Legacy Preservation: Moved all tests for deprecated, dictionary-based portrayals to
test_solara_viz_legacy.py. This now includes dedicated tests for both agent and property layer portrayals, ensuring full backward compatibility.Refactoring: Removed the redundant
test_solara_viz_updated.pyfile and the unnecessarytest_voronoi_grid_rendererfunction, consolidating all logic into the two primary test files.Testing
The test suite is now cleanly organized into two files, with all tests passing locally and in CI.
tests/visualization/test_solara_viz.py: Contains 11 tests validating the modern API andSpaceRendererfor both backends.tests/visualization/test_solara_viz_legacy.py: Contains 3 tests validating the legacy, dictionary-based APIs to ensure backward compatibility.Additional Notes
This PR strictly follows the two-file structure requested by the maintainers: one primary file for modern tests and one legacy file for deprecated features.
The high deletion count in the diff is due to the removal of the redundant intermediate file (
test_solara_viz_updated.py) and the consolidation of logic.