mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-15 10:33:06 +03:00
original test_imagefile.py
This commit is contained in:
parent
adf7b40605
commit
5b1d17575c
|
@ -118,7 +118,7 @@ the shared code in **conftest.py**.
|
||||||
|
|
||||||
- Function 2: `encode_to_file` from **ImageFile.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" />
|
<img src="report_images/deekshu_images/[BEFORE]encode_to_file.png" alt="Coverage Before" width="600" />
|
||||||
|
|
||||||
|
|
|
@ -215,44 +215,19 @@ class MockPyDecoder(ImageFile.PyDecoder):
|
||||||
|
|
||||||
|
|
||||||
class MockPyEncoder(ImageFile.PyEncoder):
|
class MockPyEncoder(ImageFile.PyEncoder):
|
||||||
last = None
|
last: MockPyEncoder | None
|
||||||
|
|
||||||
def __init__(self, mode: str, *args: Any) -> None:
|
def __init__(self, mode: str, *args: Any) -> None:
|
||||||
super().__init__(mode, *args)
|
|
||||||
self._pushes_fd = False
|
|
||||||
self.cleanup_called = False
|
|
||||||
MockPyEncoder.last = self
|
MockPyEncoder.last = self
|
||||||
|
|
||||||
|
super().__init__(mode, *args)
|
||||||
|
|
||||||
def encode(self, buffer):
|
def encode(self, buffer):
|
||||||
# Simulate encoding
|
|
||||||
if buffer is None:
|
|
||||||
raise NotImplementedError
|
|
||||||
return 1, 1, b""
|
return 1, 1, b""
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
self.cleanup_called = True
|
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
|
xoff, yoff, xsize, ysize = 10, 20, 100, 100
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user