mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-05 13:00:09 +03:00
added branch coverage calculations
This commit is contained in:
parent
0a45381c2b
commit
42abc817a8
|
@ -5,6 +5,7 @@ import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from conftest import branch_coverage
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -36,7 +37,6 @@ test_card.load()
|
||||||
# ignore it---it doesn't represent a test failure.
|
# ignore it---it doesn't represent a test failure.
|
||||||
# 'Not enough memory to handle tile data'
|
# 'Not enough memory to handle tile data'
|
||||||
|
|
||||||
|
|
||||||
def roundtrip(im: Image.Image, **options: Any) -> Image.Image:
|
def roundtrip(im: Image.Image, **options: Any) -> Image.Image:
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
im.save(out, "JPEG2000", **options)
|
im.save(out, "JPEG2000", **options)
|
||||||
|
@ -447,12 +447,15 @@ def test_plt_marker() -> None:
|
||||||
|
|
||||||
jp2_boxid = _binary.i16be(marker)
|
jp2_boxid = _binary.i16be(marker)
|
||||||
if jp2_boxid == 0xFF4F:
|
if jp2_boxid == 0xFF4F:
|
||||||
|
branch_coverage["1"] = True
|
||||||
# SOC has no length
|
# SOC has no length
|
||||||
continue
|
continue
|
||||||
elif jp2_boxid == 0xFF58:
|
elif jp2_boxid == 0xFF58:
|
||||||
|
branch_coverage["2"] = True
|
||||||
# PLT
|
# PLT
|
||||||
return
|
return
|
||||||
elif jp2_boxid == 0xFF93:
|
elif jp2_boxid == 0xFF93:
|
||||||
|
branch_coverage["3"] = True
|
||||||
pytest.fail("SOD without finding PLT first")
|
pytest.fail("SOD without finding PLT first")
|
||||||
|
|
||||||
hdr = out.read(2)
|
hdr = out.read(2)
|
||||||
|
@ -464,3 +467,4 @@ def test_9bit():
|
||||||
with Image.open("Tests/images/9bit.j2k") as im:
|
with Image.open("Tests/images/9bit.j2k") as im:
|
||||||
assert im.mode == "I;16"
|
assert im.mode == "I;16"
|
||||||
assert im.size == (128, 128)
|
assert im.size == (128, 128)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from conftest import branch_coverage
|
||||||
|
|
||||||
from .helper import (
|
from .helper import (
|
||||||
assert_image_equal,
|
assert_image_equal,
|
||||||
|
@ -25,10 +26,13 @@ def rotate(
|
||||||
out = im.rotate(angle, center=center, translate=translate, expand=1)
|
out = im.rotate(angle, center=center, translate=translate, expand=1)
|
||||||
assert out.mode == mode
|
assert out.mode == mode
|
||||||
if angle % 180 == 0:
|
if angle % 180 == 0:
|
||||||
|
branch_coverage["1"] = True
|
||||||
assert out.size == im.size
|
assert out.size == im.size
|
||||||
elif im.size == (0, 0):
|
elif im.size == (0, 0):
|
||||||
|
branch_coverage["2"] = True
|
||||||
assert out.size == im.size
|
assert out.size == im.size
|
||||||
else:
|
else:
|
||||||
|
branch_coverage["3"] = True
|
||||||
assert out.size != im.size
|
assert out.size != im.size
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,3 +158,4 @@ def test_alpha_rotate_with_fill() -> None:
|
||||||
im = im.rotate(45, expand=1, fillcolor=(255, 0, 0, 255))
|
im = im.rotate(45, expand=1, fillcolor=(255, 0, 0, 255))
|
||||||
corner = im.getpixel((0, 0))
|
corner = im.getpixel((0, 0))
|
||||||
assert corner == (255, 0, 0, 255)
|
assert corner == (255, 0, 0, 255)
|
||||||
|
|
||||||
|
|
20
conftest.py
20
conftest.py
|
@ -1,3 +1,23 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
import pytest
|
||||||
|
|
||||||
pytest_plugins = ["Tests.helper"]
|
pytest_plugins = ["Tests.helper"]
|
||||||
|
|
||||||
|
branch_coverage1 = {
|
||||||
|
"1": False,
|
||||||
|
"2": False,
|
||||||
|
"3": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def calculate_coverage():
|
||||||
|
num_branches = len(branch_coverage1)
|
||||||
|
covered_branches = sum(value is True for value in branch_coverage1.values())
|
||||||
|
|
||||||
|
coverage = (covered_branches/num_branches) * 100
|
||||||
|
|
||||||
|
return coverage
|
||||||
|
|
||||||
|
@pytest.hookimpl(tryfirst=True)
|
||||||
|
def pytest_sessionfinish(session, exitstatus):
|
||||||
|
coverage = calculate_coverage()
|
||||||
|
print("\nBRANCH COVERAGE:", coverage, "%\n")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user