Skip to content

Test the image replacement path - #78

Merged
psobot merged 1 commit into
masterfrom
psobot/test-image-replacement
Aug 8, 2026
Merged

Test the image replacement path#78
psobot merged 1 commit into
masterfrom
psobot/test-image-replacement

Conversation

@psobot

@psobot psobot commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Why

file_utils' Data/ image-replacement branch had zero test coverage, and no test in the repo imported PIL at all. That's how Image.ANTIALIAS survived there for two years after Pillow 10.0 removed it (July 2023): every user's image replacement raised AttributeError, and nothing in CI noticed.

#59 fixed the call but added no test, so the same class of breakage would go unnoticed again.

What

tests/test_image_replacement.py drives the real path against tests/data/table.key:

  • matching assets are actually rewritten
  • the replacement is scaled down to each original size variant, so one source image can stand in for every size Keynote generated
  • the original format is preserved
  • a non-matching pattern leaves the Data/ assets untouched
  • the output is still a readable Keynote archive, not merely a valid zip

No new binary fixtures — the replacement image is generated with PIL at test time.

These tests actually catch the bug

Rather than assume, I reintroduced Image.ANTIALIAS and re-ran them:

FAILED tests/test_image_replacement.py::test_matching_assets_are_rewritten
FAILED tests/test_image_replacement.py::test_replacement_is_scaled_to_each_original
FAILED tests/test_image_replacement.py::test_replacement_preserves_the_original_format
FAILED tests/test_image_replacement.py::test_output_is_still_a_readable_keynote_archive
4 failed, 1 passed

Coverage

keynote_parser/file_utils.py: 40% → 67%. Full suite 35 passed.

One line in that branch is still uncovered by design: the continue taken when a find string doesn't split into exactly two dot-separated parts. That's the #52 failure mode — a pattern like game(?:-\d+)?\.png is silently skipped. I've deliberately not pinned that behaviour down in a test, since it's a wart to fix rather than a contract to lock in.

file_utils' Data/ branch had no coverage at all, which is how Image.ANTIALIAS
survived there for two years after Pillow 10.0 removed it: every user's image
replacement raised AttributeError and nothing in CI noticed. #59 fixed the call
but added no test, so the same class of breakage would go unnoticed again.

These drive the real path against tests/data/table.key - matching assets are
rewritten, the replacement is scaled down to each original variant, the source
format is preserved, a non-matching pattern leaves the assets alone, and the
result is still a readable Keynote archive rather than merely a valid zip.

Verified the tests actually catch the bug they exist for: reintroducing
Image.ANTIALIAS fails four of the five.

Coverage of keynote_parser/file_utils.py goes from 40% to 67%.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0179M4xvAKPGrgKpy4AeCsM7
@psobot psobot mentioned this pull request Aug 8, 2026
@psobot
psobot merged commit 716e7dc into master Aug 8, 2026
4 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