From e31adc7e40442076f65a47b457f0c73040d4e7fc Mon Sep 17 00:00:00 2001 From: Duru Date: Fri, 21 Jun 2024 14:58:01 +0200 Subject: [PATCH] deekshu coverage tool and duru second func improv --- conftest.py | 8 +++++--- src/PIL/ImageCms.py | 20 ++++++++++++++++++++ src/PIL/McIdasImagePlugin.py | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index 57a5a80db..260330c28 100644 --- a/conftest.py +++ b/conftest.py @@ -4,6 +4,8 @@ import sys from PIL import Image from PIL import PdfParser +from PIL import ImageCms +from PIL import McIdasImagePlugin pytest_plugins = ["Tests.helper"] @@ -12,6 +14,8 @@ def calculate_coverage(test_name): all_branches = { "branches1": Image.branches, "branches2": PdfParser.XrefTable.branches, + "branches3": ImageCms.ImageCmsProfile.branches, + "branches4": McIdasImagePlugin.McIdasImageFile.branches, # Add more } @@ -45,6 +49,4 @@ def pytest_sessionfinish(session, exitstatus): global test_name coverage = calculate_coverage(test_name) - print("\nBRANCH COVERAGE for", test_name, ":", coverage, "%\n") - - \ No newline at end of file + print("\nBRANCH COVERAGE for", test_name, ":", coverage, "%\n") \ No newline at end of file diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 2eedf952f..70f5a5de0 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -237,6 +237,17 @@ _FLAGS = { class ImageCmsProfile: + branches = { + "1": False, + "2": False, + "3": False, + "4": False, + "5": False, + "6": False, + "7": False, + "8": False, + } + def __init__(self, profile: str | SupportsRead[bytes] | core.CmsProfile) -> None: """ :param profile: Either a string representing a filename, @@ -246,23 +257,32 @@ class ImageCmsProfile: """ if isinstance(profile, str): + ImageCmsProfile.branches["1"] = True if sys.platform == "win32": + ImageCmsProfile.branches["2"] = True profile_bytes_path = profile.encode() try: + ImageCmsProfile.branches["3"] = True profile_bytes_path.decode("ascii") except UnicodeDecodeError: + ImageCmsProfile.branches["4"] = True with open(profile, "rb") as f: + ImageCmsProfile.branches["5"] = True self._set(core.profile_frombytes(f.read())) return self._set(core.profile_open(profile), profile) elif hasattr(profile, "read"): + ImageCmsProfile.branches["6"] = True self._set(core.profile_frombytes(profile.read())) elif isinstance(profile, core.CmsProfile): + ImageCmsProfile.branches["7"] = True self._set(profile) else: + ImageCmsProfile.branches["8"] = True msg = "Invalid type for Profile" # type: ignore[unreachable] raise TypeError(msg) + def _set(self, profile: core.CmsProfile, filename: str | None = None) -> None: self.profile = profile self.filename = filename diff --git a/src/PIL/McIdasImagePlugin.py b/src/PIL/McIdasImagePlugin.py index d2a8f32e7..5bb5f1eba 100644 --- a/src/PIL/McIdasImagePlugin.py +++ b/src/PIL/McIdasImagePlugin.py @@ -31,6 +31,14 @@ def _accept(prefix: bytes) -> bool: class McIdasImageFile(ImageFile.ImageFile): + branches = { + "1": False, + "2": False, + "3": False, + "4": False, + "5": False, + } + format = "MCIDAS" format_description = "McIdas area file" @@ -40,6 +48,7 @@ class McIdasImageFile(ImageFile.ImageFile): s = self.fp.read(256) if not _accept(s) or len(s) != 256: + McIdasImageFile.branches["1"] = True msg = "not an McIdas area file" raise SyntaxError(msg) @@ -48,16 +57,20 @@ class McIdasImageFile(ImageFile.ImageFile): # get mode if w[11] == 1: + McIdasImageFile.branches["2"] = True mode = rawmode = "L" elif w[11] == 2: + McIdasImageFile.branches["3"] = True # FIXME: add memory map support mode = "I" rawmode = "I;16B" elif w[11] == 4: + McIdasImageFile.branches["4"] = True # FIXME: add memory map support mode = "I" rawmode = "I;32B" else: + McIdasImageFile.branches["5"] = True msg = "unsupported McIdas format" raise SyntaxError(msg) @@ -76,3 +89,4 @@ class McIdasImageFile(ImageFile.ImageFile): Image.register_open(McIdasImageFile.format, McIdasImageFile, _accept) # no default extension +