test: Expand coverage to 90% for v1.5.0
Added 3 MPO format tests per v1.5.0 Phase 5 requirements: - test_mpo_detection_and_conversion: Verify MPO->JPEG conversion - test_mpo_dimensions_preserved: Verify dimensions maintained - test_mpo_full_upload_flow: Test complete upload workflow MPO (Multi-Picture Object) format handling was implemented in v1.4.2 but was previously untested. These tests ensure the format detection and JPEG conversion work correctly for iPhone portrait/depth photos. Test count: 924 -> 927 tests (all passing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -74,6 +74,31 @@ def create_test_heic(width=800, height=600):
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
def create_test_mpo(width=800, height=600):
|
||||
"""
|
||||
Generate test MPO (Multi-Picture Object) image
|
||||
|
||||
MPO format is used by iPhones for depth/portrait photos. It contains
|
||||
multiple JPEG images in one file. For testing, we create a simple MPO
|
||||
with a single frame.
|
||||
|
||||
Args:
|
||||
width: Image width in pixels
|
||||
height: Image height in pixels
|
||||
|
||||
Returns:
|
||||
Bytes of MPO image data
|
||||
"""
|
||||
# Create a simple RGB image
|
||||
img = Image.new('RGB', (width, height), color='green')
|
||||
|
||||
# Save as MPO (Pillow will handle this correctly)
|
||||
buffer = io.BytesIO()
|
||||
img.save(buffer, format='MPO', quality=95)
|
||||
buffer.seek(0)
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
class TestImageValidation:
|
||||
"""Test validate_image function"""
|
||||
|
||||
@@ -236,6 +261,54 @@ class TestHEICSupport:
|
||||
assert saved_img.format == 'JPEG'
|
||||
|
||||
|
||||
class TestMPOSupport:
|
||||
"""Test MPO (Multi-Picture Object) image format support (v1.5.0 Phase 5)"""
|
||||
|
||||
def test_mpo_detection_and_conversion(self):
|
||||
"""Test MPO file is detected and converted to JPEG"""
|
||||
mpo_data = create_test_mpo(800, 600)
|
||||
file_data, mime_type, width, height = validate_image(mpo_data, 'test.mpo')
|
||||
|
||||
# Should be converted to JPEG
|
||||
assert mime_type == 'image/jpeg'
|
||||
assert width == 800
|
||||
assert height == 600
|
||||
# Verify it's actually JPEG by opening it
|
||||
img = Image.open(io.BytesIO(file_data))
|
||||
assert img.format == 'JPEG'
|
||||
# Note: MPO with single frame may have identical bytes to JPEG
|
||||
# The important part is the format detection and MIME type correction
|
||||
|
||||
def test_mpo_dimensions_preserved(self):
|
||||
"""Test MPO conversion preserves dimensions"""
|
||||
mpo_data = create_test_mpo(1024, 768)
|
||||
file_data, mime_type, width, height = validate_image(mpo_data, 'photo.mpo')
|
||||
|
||||
assert width == 1024
|
||||
assert height == 768
|
||||
assert mime_type == 'image/jpeg'
|
||||
|
||||
def test_mpo_full_upload_flow(self, app):
|
||||
"""Test complete MPO upload through save_media"""
|
||||
mpo_data = create_test_mpo(800, 600)
|
||||
|
||||
with app.app_context():
|
||||
media_info = save_media(mpo_data, 'iphone_portrait.mpo')
|
||||
|
||||
# Should be saved as JPEG
|
||||
assert media_info['mime_type'] == 'image/jpeg'
|
||||
assert media_info['width'] == 800
|
||||
assert media_info['height'] == 600
|
||||
|
||||
# Verify file was saved
|
||||
media_path = Path(app.config['DATA_PATH']) / 'media' / media_info['path']
|
||||
assert media_path.exists()
|
||||
|
||||
# Verify it's actually a JPEG file
|
||||
saved_img = Image.open(media_path)
|
||||
assert saved_img.format == 'JPEG'
|
||||
|
||||
|
||||
class TestImageOptimization:
|
||||
"""Test optimize_image function"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user