Skip to content

Fix test_render_raster_layers brittle base64 assertions #313#314

Closed
Tejasv-Singh wants to merge 2 commits intomesa:mainfrom
Tejasv-Singh:fix-test-render-raster-layers
Closed

Fix test_render_raster_layers brittle base64 assertions #313#314
Tejasv-Singh wants to merge 2 commits intomesa:mainfrom
Tejasv-Singh:fix-test-render-raster-layers

Conversation

@Tejasv-Singh
Copy link
Contributor

Summary

Fixes frail rendering tests on Windows with Python 3.14. tests/test_MapModule.py::TestMapModule::test_render_raster_layers was asserting a strict match to statically hardcoded base64 PNG data-url representations which fundamentally differ across zlib implementations.

Bug / Issue

Resolves #313
Relates to #311

The test_render_raster_layers test failed on Windows/Python 3.14 because the zlib-ng compressor (native to Py3.14 on Windows) outputs valid structural DEFLATE strings that objectively do not match byte-for-byte to the hardcoded dictionary strings being strictly mapped via assertDictEqual. In reality, the rendering was visually identical but algorithmically compressed differently.

Implementation

  • Replaced the brittle exact dictionary base64 regex matching.
  • Validated core properties of expected PNG rendering headers (data:image/png;base64,).
  • Used Python's builtin base64, io and PIL.Image (Pillow) to decode the base64 URL bytes into proper physical memory blocks representing the expected 1x1 size map layers.
  • Directly asserted getpixel((0,0)) values mapping back to natively checking RGBA matrix constraints (e.g., (255, 255, 255, 255) and (0, 0, 0, 255)) instead of strictly enforcing raw string hashes.

Testing

  • Ran .venv/bin/pytest tests/test_MapModule.py locally on the Windows/Python 3.14 equivalence target and achieved deterministic success (100%) compared to previous CI framework failures.
  • Ensured backend testing natively validates local raster geospatial datasets accurately.

Do let me know if it needs more improvements or any modifications 🙌

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.09%. Comparing base (47cf55f) to head (a4ea69c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #314   +/-   ##
=======================================
  Coverage   78.09%   78.09%           
=======================================
  Files          10       10           
  Lines         995      995           
  Branches      158      158           
=======================================
  Hits          777      777           
  Misses        177      177           
  Partials       41       41           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tejasv-Singh
Copy link
Contributor Author

Hey @EwoutH and @wang-boyu! It looks like I was working on this at the exact same time PR #311 was merged. I've resolved the merge conflicts on my end.

My PR fixes the #313 issue by doing a semantic pixel check using PIL.Image rather than mocking the encoder. Let me know if you prefer this semantic validation approach and want to review this, or if you are fully happy with the mock approach merged in #311, in which case I can just go ahead and close this PR!

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.

test_render_raster_layers is brittle because it asserts exact base64 PNG bytes (fails on Windows + Python 3.14)

1 participant