original test_imagefile.py

This commit is contained in:
Deekshu Kare 2024-06-27 16:26:10 +02:00
parent adf7b40605
commit 5b1d17575c
2 changed files with 5 additions and 30 deletions

View File

@ -118,7 +118,7 @@ the shared code in **conftest.py**.
- Function 2: `encode_to_file` from **ImageFile.py**
[Link to the commit](PENDING) - how to show the diff patch
[Link to the commit](https://github.com/jovanovicisidora/Pillow-SEP/commit/52965eed2de5ca44eeb6c6dfb1f11778d369c6f7) - how to show the diff patch
<img src="report_images/deekshu_images/[BEFORE]encode_to_file.png" alt="Coverage Before" width="600" />

View File

@ -215,44 +215,19 @@ class MockPyDecoder(ImageFile.PyDecoder):
class MockPyEncoder(ImageFile.PyEncoder):
last = None
last: MockPyEncoder | None
def __init__(self, mode: str, *args: Any) -> None:
super().__init__(mode, *args)
self._pushes_fd = False
self.cleanup_called = False
MockPyEncoder.last = self
super().__init__(mode, *args)
def encode(self, buffer):
# Simulate encoding
if buffer is None:
raise NotImplementedError
return 1, 1, b""
def cleanup(self) -> None:
self.cleanup_called = True
def test_encode_to_file() -> None:
encoder = MockPyEncoder("RGBA")
with pytest.raises(NotImplementedError):
encoder.encode_to_file(None, None)
encoder._pushes_fd = True
with pytest.raises(NotImplementedError):
encoder.encode_to_file(None, None)
buffer = BytesIO(b"\x00" * 10)
encoder._pushes_fd = False
encoder.encode = lambda buffer: (1, 1, b"")
try:
encoder.encode_to_file(buffer, None)
except NotImplementedError:
pass
encoder.encode = lambda buffer: (_ for _ in ()).throw(NotImplementedError)
with pytest.raises(NotImplementedError):
encoder.encode_to_file(buffer, None)
xoff, yoff, xsize, ysize = 10, 20, 100, 100
@ -421,4 +396,4 @@ class TestPyEncoder(CodecsTest):
def test_zero_height(self) -> None:
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/zero_height.j2k")
Image.open("Tests/images/zero_height.j2k")