mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-25 03:23:41 +03:00
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from io import BytesIO
|
|
|
|
import pytest
|
|
|
|
from PIL import Image, MpegImagePlugin
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
def test_identify() -> None:
|
|
# Arrange
|
|
b = BytesIO(b"\x00\x00\x01\xb3\x01\x00\x01")
|
|
|
|
# Act
|
|
with Image.open(b) as im:
|
|
# Assert
|
|
assert im.format == "MPEG"
|
|
|
|
assert im.mode == "RGB"
|
|
assert im.size == (16, 1)
|
|
|
|
|
|
def test_invalid_file() -> None:
|
|
# Arrange
|
|
invalid_file = "Tests/images/flower.jpg"
|
|
|
|
# Act / Assert
|
|
with pytest.raises(SyntaxError):
|
|
MpegImagePlugin.MpegImageFile(invalid_file)
|
|
|
|
|
|
def test_load() -> None:
|
|
# Arrange
|
|
b = BytesIO(b"\x00\x00\x01\xb3\x01\x00\x01")
|
|
|
|
with Image.open(b) as im:
|
|
# Act / Assert: cannot load
|
|
with pytest.raises(OSError):
|
|
im.load()
|
|
|
|
|
|
def test_peek_with_negative_c() -> None:
|
|
fp = MagicMock()
|
|
|
|
return_values = [-1, 255]
|
|
|
|
with patch.object(MpegImagePlugin.BitStream, 'next', side_effect=return_values):
|
|
bitstream = MpegImagePlugin.BitStream(fp)
|
|
result = bitstream.peek(8)
|
|
|
|
assert result == 255
|