mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-04 20:40:11 +03:00
Merge branch 'main' into duru
This commit is contained in:
commit
914d6b981e
|
@ -5,6 +5,7 @@ import re
|
|||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from conftest import branch_coverage1
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -36,7 +37,6 @@ test_card.load()
|
|||
# ignore it---it doesn't represent a test failure.
|
||||
# 'Not enough memory to handle tile data'
|
||||
|
||||
|
||||
def roundtrip(im: Image.Image, **options: Any) -> Image.Image:
|
||||
out = BytesIO()
|
||||
im.save(out, "JPEG2000", **options)
|
||||
|
@ -447,12 +447,15 @@ def test_plt_marker() -> None:
|
|||
|
||||
jp2_boxid = _binary.i16be(marker)
|
||||
if jp2_boxid == 0xFF4F:
|
||||
branch_coverage1["1"] = True
|
||||
# SOC has no length
|
||||
continue
|
||||
elif jp2_boxid == 0xFF58:
|
||||
branch_coverage1["2"] = True
|
||||
# PLT
|
||||
return
|
||||
elif jp2_boxid == 0xFF93:
|
||||
branch_coverage1["3"] = True
|
||||
pytest.fail("SOD without finding PLT first")
|
||||
|
||||
hdr = out.read(2)
|
||||
|
@ -464,3 +467,4 @@ def test_9bit():
|
|||
with Image.open("Tests/images/9bit.j2k") as im:
|
||||
assert im.mode == "I;16"
|
||||
assert im.size == (128, 128)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
from conftest import branch_coverage1
|
||||
|
||||
from .helper import (
|
||||
assert_image_equal,
|
||||
|
@ -25,10 +26,13 @@ def rotate(
|
|||
out = im.rotate(angle, center=center, translate=translate, expand=1)
|
||||
assert out.mode == mode
|
||||
if angle % 180 == 0:
|
||||
branch_coverage1["1"] = True
|
||||
assert out.size == im.size
|
||||
elif im.size == (0, 0):
|
||||
branch_coverage1["2"] = True
|
||||
assert out.size == im.size
|
||||
else:
|
||||
branch_coverage1["3"] = True
|
||||
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))
|
||||
corner = im.getpixel((0, 0))
|
||||
assert corner == (255, 0, 0, 255)
|
||||
|
||||
|
|
20
conftest.py
20
conftest.py
|
@ -1,3 +1,23 @@
|
|||
from __future__ import annotations
|
||||
import pytest
|
||||
|
||||
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