Skip to content

Verify metadata stripping with robust test case#31

Merged
bstag merged 3 commits intomainfrom
test-metadata-stripping-fix-2778856619786087056
Jan 12, 2026
Merged

Verify metadata stripping with robust test case#31
bstag merged 3 commits intomainfrom
test-metadata-stripping-fix-2778856619786087056

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

Improved the test_metadata_strip test case in tests/test_processor.py to rigorously verify the metadata stripping functionality of ImageProcessor.process_and_save.

Previously, the test only ensured that the function ran without errors. The updated test:

  1. Creates a synthetic image with specific EXIF data (Make tag).
  2. Saves and reloads this image to simulate a real-world file load (ensuring info['exif'] is populated correctly for the processor).
  3. Calls process_and_save with strip_metadata=True.
  4. Asserts that the resulting image does not contain the injected EXIF tag and that the raw 'exif' key is absent from the image info dictionary.

This confirms the "Bolt Optimization" in src/processor.py works as intended.


PR created automatically by Jules for task 2778856619786087056 started by @bstag

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.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@bstag bstag marked this pull request as ready for review January 12, 2026 16:43
Copilot AI review requested due to automatic review settings January 12, 2026 16:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +110
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'])
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
bstag and others added 2 commits January 12, 2026 10:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bstag bstag merged commit d6d097a into main Jan 12, 2026
@bstag bstag deleted the test-metadata-stripping-fix-2778856619786087056 branch January 12, 2026 16:50
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.

2 participants