branchcov fix

This commit is contained in:
Duru 2024-06-22 01:30:13 +02:00
parent 1881f22e89
commit b72a607b01
2 changed files with 2 additions and 17 deletions

Binary file not shown.

View File

@ -215,12 +215,13 @@ class MockPyDecoder(ImageFile.PyDecoder):
class MockPyEncoder(ImageFile.PyEncoder): class MockPyEncoder(ImageFile.PyEncoder):
last: MockPyEncoder | None last = None # Add this line
def __init__(self, mode: str, *args: Any) -> None: def __init__(self, mode: str, *args: Any) -> None:
super().__init__(mode, *args) super().__init__(mode, *args)
self._pushes_fd = False self._pushes_fd = False
self.cleanup_called = False self.cleanup_called = False
MockPyEncoder.last = self # Update this line
def encode(self, buffer): def encode(self, buffer):
# Simulate encoding # Simulate encoding
@ -257,22 +258,6 @@ def test_encode_to_file() -> None:
with pytest.raises(NotImplementedError): with pytest.raises(NotImplementedError):
encoder.encode_to_file(buffer, None) encoder.encode_to_file(buffer, None)
# Case: cleanup is called after exception
encoder.encode = lambda buffer: (_ for _ in ()).throw(ValueError)
with pytest.raises(ValueError):
encoder.encode_to_file(buffer, None)
assert encoder.cleanup_called
# Case: encode returns unexpected values
encoder.encode = lambda buffer: (None, None, None)
with pytest.raises(ValueError):
encoder.encode_to_file(buffer, None)
# Case: UnidentifiedImageError
with pytest.raises(UnidentifiedImageError):
encoder.encode_to_file(buffer, BytesIO(b"\x00" * 10))
xoff, yoff, xsize, ysize = 10, 20, 100, 100 xoff, yoff, xsize, ysize = 10, 20, 100, 100