Verify metadata stripping with robust test case#31
Conversation
Updated `test_metadata_strip` in `tests/test_processor.py` to robustly verify that EXIF data is removed. The previous test was only checking for successful execution. The new test injects EXIF data, processes the image, and asserts that the metadata is absent in the output.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR enhances the metadata stripping test in tests/test_processor.py to provide more rigorous validation of the ImageProcessor.process_and_save method's metadata stripping functionality. Previously, the test only verified that the function executed without errors. The improved test now creates a synthetic JPEG image with actual EXIF data (Make tag), processes it with strip_metadata=True, and explicitly verifies that the metadata has been removed from the output.
Changes:
- Replaced basic execution test with comprehensive metadata stripping validation
- Added EXIF data creation and verification logic using PIL's EXIF handling
- Implemented assertions to check both the EXIF dictionary and raw info dictionary
| img.save(tmp, 'JPEG', exif=exif.tobytes()) | ||
| tmp.seek(0) | ||
|
|
||
| loaded_img = Image.open(tmp) |
There was a problem hiding this comment.
The test should verify that the EXIF data is actually present in loaded_img before calling process_and_save. Add an assertion like self.assertEqual(loaded_img.getexif().get(271), "TestMake") after line 96 to confirm the test setup is correct and that the EXIF data was successfully embedded. This ensures the test is actually testing metadata stripping rather than just passing because the metadata was never there in the first place.
tests/test_processor.py
Outdated
| def test_metadata_strip(self): | ||
| # Create image with dummy info (hard to inject real EXIF without extra libs, | ||
| # but we can verify the function runs and returns a valid image without error) | ||
| # A more robust test would require loading an image with known EXIF. | ||
| # For now, we verify the output is a clean new image. | ||
| output = ImageProcessor.process_and_save(self.img, 'PNG', strip_metadata=True) | ||
| # 1. Create a "real" image with EXIF data in memory | ||
| img = Image.new('RGB', (100, 100), color='red') | ||
| exif = img.getexif() | ||
| exif[271] = "TestMake" # Make | ||
|
|
||
| # Save to bytes to simulate a loaded file | ||
| tmp = io.BytesIO() | ||
| img.save(tmp, 'JPEG', exif=exif.tobytes()) | ||
| tmp.seek(0) | ||
|
|
||
| loaded_img = Image.open(tmp) | ||
|
|
||
| # 2. Call process_and_save with strip_metadata=True | ||
| output = ImageProcessor.process_and_save(loaded_img, 'JPEG', strip_metadata=True) | ||
| output.seek(0) | ||
| self.assertTrue(output.getbuffer().nbytes > 0) | ||
|
|
||
| # 3. Load the output and verify EXIF/metadata is absent | ||
| result_img = Image.open(output) | ||
|
|
||
| # Check getexif | ||
| result_exif = result_img.getexif() | ||
| self.assertIsNone(result_exif.get(271)) | ||
|
|
||
| # Check info dictionary for 'exif' key (raw bytes) | ||
| self.assertTrue('exif' not in result_img.info or not result_img.info['exif']) |
There was a problem hiding this comment.
Consider adding a complementary test case to verify that metadata is preserved when strip_metadata=False. This would ensure the feature works correctly in both directions and prevents regressions. The test could create an image with EXIF data, call process_and_save with strip_metadata=False, and assert that the EXIF tag 271 is still present in the result.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Improved the
test_metadata_striptest case intests/test_processor.pyto rigorously verify the metadata stripping functionality ofImageProcessor.process_and_save.Previously, the test only ensured that the function ran without errors. The updated test:
info['exif']is populated correctly for the processor).process_and_savewithstrip_metadata=True.This confirms the "Bolt Optimization" in
src/processor.pyworks as intended.PR created automatically by Jules for task 2778856619786087056 started by @bstag