mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 20:03:20 +03:00
coverage tool implemented
This commit is contained in:
parent
badd4b6ccb
commit
0372c50a4d
|
@ -4,6 +4,7 @@ import sys
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import PdfParser
|
from PIL import PdfParser
|
||||||
|
from PIL import SpiderImagePlugin
|
||||||
|
|
||||||
pytest_plugins = ["Tests.helper"]
|
pytest_plugins = ["Tests.helper"]
|
||||||
|
|
||||||
|
@ -12,6 +13,8 @@ def calculate_coverage(test_name):
|
||||||
all_branches = {
|
all_branches = {
|
||||||
"branches1": Image.branches,
|
"branches1": Image.branches,
|
||||||
"branches2": PdfParser.XrefTable.branches,
|
"branches2": PdfParser.XrefTable.branches,
|
||||||
|
"branches3": SpiderImagePlugin.branches1,
|
||||||
|
"branches4": SpiderImagePlugin.branches2,
|
||||||
# Add more
|
# Add more
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,4 +50,3 @@ def pytest_sessionfinish(session, exitstatus):
|
||||||
coverage = calculate_coverage(test_name)
|
coverage = calculate_coverage(test_name)
|
||||||
print("\nBRANCH COVERAGE for", test_name, ":", coverage, "%\n")
|
print("\nBRANCH COVERAGE for", test_name, ":", coverage, "%\n")
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,33 @@ from typing import IO, TYPE_CHECKING
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
|
|
||||||
|
|
||||||
|
branches1 = {
|
||||||
|
"1": False,
|
||||||
|
"2": False,
|
||||||
|
"3": False,
|
||||||
|
"4": False,
|
||||||
|
"5": False,
|
||||||
|
"6": False,
|
||||||
|
"7": False,
|
||||||
|
"8": False,
|
||||||
|
"9": False,
|
||||||
|
"10": False,
|
||||||
|
"11": False,
|
||||||
|
"12": False,
|
||||||
|
"13": False,
|
||||||
|
"14": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
branches2 = {
|
||||||
|
"1": False,
|
||||||
|
"2": False,
|
||||||
|
"3": False,
|
||||||
|
"4": False,
|
||||||
|
"5": False,
|
||||||
|
"6": False,
|
||||||
|
"7": False,
|
||||||
|
}
|
||||||
|
|
||||||
def isInt(f):
|
def isInt(f):
|
||||||
try:
|
try:
|
||||||
i = int(f)
|
i = int(f)
|
||||||
|
@ -104,35 +131,52 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
f = self.fp.read(n)
|
f = self.fp.read(n)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
branches1["1"] = True
|
||||||
self.bigendian = 1
|
self.bigendian = 1
|
||||||
t = struct.unpack(">27f", f) # try big-endian first
|
t = struct.unpack(">27f", f) # try big-endian first
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
|
|
||||||
if hdrlen == 0:
|
if hdrlen == 0:
|
||||||
|
branches1["2"] = True
|
||||||
self.bigendian = 0
|
self.bigendian = 0
|
||||||
t = struct.unpack("<27f", f) # little-endian
|
t = struct.unpack("<27f", f) # little-endian
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
|
else: # ADDED FOR BRANCH MARKING
|
||||||
|
branches1["3"] = True
|
||||||
|
|
||||||
if hdrlen == 0:
|
if hdrlen == 0:
|
||||||
|
branches1["4"] = True
|
||||||
msg = "not a valid Spider file"
|
msg = "not a valid Spider file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
else: # ADDED FOR BRANCH MARKING
|
||||||
|
branches1["5"] = True
|
||||||
|
|
||||||
except struct.error as e:
|
except struct.error as e:
|
||||||
|
branches1["6"] = True
|
||||||
msg = "not a valid Spider file"
|
msg = "not a valid Spider file"
|
||||||
raise SyntaxError(msg) from e
|
raise SyntaxError(msg) from e
|
||||||
|
|
||||||
h = (99,) + t # add 1 value : spider header index starts at 1
|
h = (99,) + t # add 1 value : spider header index starts at 1
|
||||||
iform = int(h[5])
|
iform = int(h[5])
|
||||||
|
|
||||||
if iform != 1:
|
if iform != 1:
|
||||||
|
branches1["7"] = True
|
||||||
msg = "not a Spider 2D image"
|
msg = "not a Spider 2D image"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
else: # ADDED FOR BRANCH MARKING
|
||||||
|
branches1["8"] = True
|
||||||
|
|
||||||
self._size = int(h[12]), int(h[2]) # size in pixels (width, height)
|
self._size = int(h[12]), int(h[2]) # size in pixels (width, height)
|
||||||
self.istack = int(h[24])
|
self.istack = int(h[24])
|
||||||
self.imgnumber = int(h[27])
|
self.imgnumber = int(h[27])
|
||||||
|
|
||||||
if self.istack == 0 and self.imgnumber == 0:
|
if self.istack == 0 and self.imgnumber == 0:
|
||||||
|
branches1["9"] = True
|
||||||
# stk=0, img=0: a regular 2D image
|
# stk=0, img=0: a regular 2D image
|
||||||
offset = hdrlen
|
offset = hdrlen
|
||||||
self._nimages = 1
|
self._nimages = 1
|
||||||
elif self.istack > 0 and self.imgnumber == 0:
|
elif self.istack > 0 and self.imgnumber == 0:
|
||||||
|
branches1["10"] = True
|
||||||
# stk>0, img=0: Opening the stack for the first time
|
# stk>0, img=0: Opening the stack for the first time
|
||||||
self.imgbytes = int(h[12]) * int(h[2]) * 4
|
self.imgbytes = int(h[12]) * int(h[2]) * 4
|
||||||
self.hdrlen = hdrlen
|
self.hdrlen = hdrlen
|
||||||
|
@ -141,16 +185,20 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
offset = hdrlen * 2
|
offset = hdrlen * 2
|
||||||
self.imgnumber = 1
|
self.imgnumber = 1
|
||||||
elif self.istack == 0 and self.imgnumber > 0:
|
elif self.istack == 0 and self.imgnumber > 0:
|
||||||
|
branches1["11"] = True
|
||||||
# stk=0, img>0: an image within the stack
|
# stk=0, img>0: an image within the stack
|
||||||
offset = hdrlen + self.stkoffset
|
offset = hdrlen + self.stkoffset
|
||||||
self.istack = 2 # So Image knows it's still a stack
|
self.istack = 2 # So Image knows it's still a stack
|
||||||
else:
|
else:
|
||||||
|
branches1["12"] = True
|
||||||
msg = "inconsistent stack header values"
|
msg = "inconsistent stack header values"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
||||||
if self.bigendian:
|
if self.bigendian:
|
||||||
|
branches1["13"] = True
|
||||||
self.rawmode = "F;32BF"
|
self.rawmode = "F;32BF"
|
||||||
else:
|
else:
|
||||||
|
branches1["14"] = True
|
||||||
self.rawmode = "F;32F"
|
self.rawmode = "F;32F"
|
||||||
self._mode = "F"
|
self._mode = "F"
|
||||||
|
|
||||||
|
@ -174,10 +222,18 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def seek(self, frame: int) -> None:
|
def seek(self, frame: int) -> None:
|
||||||
if self.istack == 0:
|
if self.istack == 0:
|
||||||
|
branches2["1"] = True
|
||||||
msg = "attempt to seek in a non-stack file"
|
msg = "attempt to seek in a non-stack file"
|
||||||
raise EOFError(msg)
|
raise EOFError(msg)
|
||||||
|
else: # ADDED FOR BRANCH MARKING
|
||||||
|
branches2["2"] = True
|
||||||
|
|
||||||
if not self._seek_check(frame):
|
if not self._seek_check(frame):
|
||||||
|
branches2["3"] = True
|
||||||
return
|
return
|
||||||
|
else: # ADDED FOR BRANCH MARKING
|
||||||
|
branches2["4"] = True
|
||||||
|
|
||||||
self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes)
|
self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes)
|
||||||
self.fp = self._fp
|
self.fp = self._fp
|
||||||
self.fp.seek(self.stkoffset)
|
self.fp.seek(self.stkoffset)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user