mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-22 02:01:59 +03:00
conftest coverage tool fix and pdfparser function coverage
This commit is contained in:
parent
d023c02904
commit
27c7ac4dad
28
conftest.py
28
conftest.py
|
@ -3,22 +3,30 @@ import pytest
|
|||
import sys
|
||||
|
||||
from PIL import Image
|
||||
from PIL import PdfParser
|
||||
|
||||
pytest_plugins = ["Tests.helper"]
|
||||
|
||||
|
||||
def calculate_coverage(test_name):
|
||||
branch = Image.branches
|
||||
branches = Image.branches
|
||||
num_branches = len(branches)
|
||||
branch_covered = {key: value for key, value in branches.items() if value is True}
|
||||
sum_branches = len(branch_covered)
|
||||
coverage = (sum_branches/num_branches) * 100
|
||||
print(f"\nBranches covered: {sum_branches}")
|
||||
print(f"\nTotal branches: {num_branches}")
|
||||
print("\nBRANCH COVERAGE:", coverage, "%\n")
|
||||
return coverage
|
||||
all_branches = {
|
||||
"branches1": Image.branches,
|
||||
"branches2": PdfParser.XrefTable.branches,
|
||||
# Add more
|
||||
}
|
||||
|
||||
for name, branches in all_branches.items():
|
||||
num_branches = len(branches)
|
||||
branch_covered = {key: value for key, value in branches.items() if value is True}
|
||||
sum_branches = len(branch_covered)
|
||||
coverage = (sum_branches / num_branches) * 100
|
||||
|
||||
print(f"\n{name} - Branches covered: {sum_branches}")
|
||||
print(f"{name} - Total branches: {num_branches}")
|
||||
print(f"{name} - BRANCH COVERAGE: {coverage}%\n")
|
||||
|
||||
|
||||
return all_branches["branches1"]
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True)
|
||||
|
|
|
@ -67,6 +67,13 @@ except ImportError:
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
branches = {
|
||||
"1": False,
|
||||
"2": False,
|
||||
"3": False,
|
||||
"4": False,
|
||||
"5": False,
|
||||
}
|
||||
|
||||
class DecompressionBombWarning(RuntimeWarning):
|
||||
pass
|
||||
|
@ -537,14 +544,6 @@ class Image:
|
|||
self.pyaccess = None
|
||||
self._exif = None
|
||||
|
||||
branches = {
|
||||
"1": False,
|
||||
"2": False,
|
||||
"3": False,
|
||||
"4": False,
|
||||
"5": False,
|
||||
}
|
||||
|
||||
@property
|
||||
def width(self) -> int:
|
||||
return self.size[0]
|
||||
|
|
|
@ -112,6 +112,14 @@ class IndirectObjectDef(IndirectReference):
|
|||
|
||||
|
||||
class XrefTable:
|
||||
|
||||
branches = {
|
||||
"1": False,
|
||||
"2": False,
|
||||
"3": False,
|
||||
"4": False,
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.existing_entries = {} # object ID => (offset, generation)
|
||||
self.new_entries = {} # object ID => (offset, generation)
|
||||
|
@ -134,15 +142,19 @@ class XrefTable:
|
|||
|
||||
def __delitem__(self, key):
|
||||
if key in self.new_entries:
|
||||
XrefTable.branches["1"] = True
|
||||
generation = self.new_entries[key][1] + 1
|
||||
del self.new_entries[key]
|
||||
self.deleted_entries[key] = generation
|
||||
elif key in self.existing_entries:
|
||||
XrefTable.branches["2"] = True
|
||||
generation = self.existing_entries[key][1] + 1
|
||||
self.deleted_entries[key] = generation
|
||||
elif key in self.deleted_entries:
|
||||
XrefTable.branches["3"] = True
|
||||
generation = self.deleted_entries[key]
|
||||
else:
|
||||
XrefTable.branches["4"] = True
|
||||
msg = f"object ID {key} cannot be deleted because it doesn't exist"
|
||||
raise IndexError(msg)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user