Skip to content

test: compare snapshots by what they draw, not how they were encoded - #87

Merged
sjquant merged 1 commit into
mainfrom
snapshot-compare-pixels
Aug 7, 2026
Merged

test: compare snapshots by what they draw, not how they were encoded#87
sjquant merged 1 commit into
mainfrom
snapshot-compare-pixels

Conversation

@sjquant

@sjquant sjquant commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Why

A PNG carries a deflate stream, and the same pixels compress to different bytes across zlib builds. The snapshot suite compared the files byte for byte, so it was testing whichever encoder happened to be installed rather than what the renderer drew.

The flat-colour snapshot makes it concrete: a fresh render of Canvas(200, 150).background(color="#3498db") differs from the stored file in 332 bytes of IDAT while being pixel-for-pixel identical — same dimensions, same mode, same 469-byte file length, same chunk layout.

Changes

  • Snapshots compare as images. The stored value carries the comparison, so none of the 117 assertions change and --inline-snapshot=create/fix still writes real PNGs

What this does not fix

tests/test_rendering.py is excluded from CI, and the corpus has drifted while nobody was watching. On Linux with locked dependencies it reports 68 stale snapshots; this change accounts for 7 of them, and the other 61 differ in actual pixels. The two hard failures are environmental — one needs network for a URL image, one needs onnxruntime, which has no cp310 wheel.

Regenerating those 61 would bless whatever the renderer currently draws in 61 cases nobody has looked at, so it wants a person's eye rather than a --inline-snapshot=fix run. This change is the prerequisite: once the corpus is current, it stays current across dependency bumps instead of drifting again, and the CI ignore can come off.

A PNG carries a deflate stream, and the same pixels compress to different
bytes across zlib builds. The snapshot suite compared the files byte for
byte, so it was testing whichever encoder happened to be installed: the
solid-colour snapshot, a 200x150 flat fill, differs from a fresh render in
332 bytes of IDAT while being pixel-for-pixel identical, same dimensions,
same mode, same file length.

Snapshots now compare as images. Nothing in the tests changes, because the
stored value is what carries the comparison.
@sjquant
sjquant merged commit be51af9 into main Aug 7, 2026
3 checks passed
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