From 5701d33cbb789342ca781769d4ba7cd323c9255e Mon Sep 17 00:00:00 2001 From: isidorajovanovic Date: Fri, 21 Jun 2024 22:10:27 +0200 Subject: [PATCH] implemented the coverage tool on _save instead of seek --- conftest.py | 2 +- src/PIL/SpiderImagePlugin.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/conftest.py b/conftest.py index a325dccfa..e05c0f13c 100644 --- a/conftest.py +++ b/conftest.py @@ -14,7 +14,7 @@ def calculate_coverage(test_name): "branches1": Image.branches, "branches2": PdfParser.XrefTable.branches, "branches3": SpiderImagePlugin.SpiderImageFile.branches1, - "branches4": SpiderImagePlugin.SpiderImageFile.branches2, + "branches4": SpiderImagePlugin.branches2, # Add more } diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 23cca4a8f..74047aaaf 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -56,6 +56,13 @@ def isInt(f): iforms = [1, 3, -11, -12, -21, -22] +branches2 = { + "1": False, + "2": False, + "3": False, + "4": False +} + # There is no magic number to identify Spider files, so just check a # series of header locations to see if they have reasonable values. @@ -116,13 +123,6 @@ class SpiderImageFile(ImageFile.ImageFile): "14": False } - branches2 = { - "1": False, - "2": False, - "3": False, - "4": False - } - def _open(self) -> None: # check header n = 27 * 4 # read 27 float values @@ -220,17 +220,11 @@ class SpiderImageFile(ImageFile.ImageFile): def seek(self, frame: int) -> None: if self.istack == 0: - SpiderImageFile.branches2["1"] = True msg = "attempt to seek in a non-stack file" raise EOFError(msg) - else: # ADDED FOR BRANCH MARKING - SpiderImageFile.branches2["2"] = True if not self._seek_check(frame): - SpiderImageFile.branches2["3"] = True return - else: # ADDED FOR BRANCH MARKING - SpiderImageFile.branches2["4"] = True self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes) self.fp = self._fp @@ -319,12 +313,18 @@ def makeSpiderHeader(im: Image.Image) -> list[bytes]: def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: if im.mode[0] != "F": + branches2["1"] = True im = im.convert("F") + else: + branches2["2"] = True hdr = makeSpiderHeader(im) if len(hdr) < 256: + branches2["3"] = True msg = "Error creating Spider header" raise OSError(msg) + else: + branches2["4"] = True # write the SPIDER header fp.writelines(hdr)