Skip to content

Commit afd1f53

Browse files
committed
Add edge-case tests for getbbox
1 parent 87181ef commit afd1f53

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Tests/test_image_getbbox.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ def check(im: Image.Image, fill_color: int | tuple[int, ...]) -> None:
4444
check(im, (255, 255))
4545

4646

47+
@pytest.mark.parametrize("mode", ("L", "RGB", "RGBA", "I", "F"))
48+
@pytest.mark.parametrize(
49+
"box",
50+
(
51+
# content flush against each edge, and single pixels in each corner,
52+
# to exercise the exact-edge scans in each stage of ImagingGetBBox
53+
(0, 0, 1, 1), # single pixel, top-left
54+
(99, 0, 100, 1), # single pixel, top-right
55+
(0, 99, 1, 100), # single pixel, bottom-left
56+
(99, 99, 100, 100), # single pixel, bottom-right
57+
(0, 0, 100, 1), # full top row
58+
(0, 99, 100, 100), # full bottom row
59+
(0, 0, 1, 100), # full left column
60+
(99, 0, 100, 100), # full right column
61+
(40, 40, 60, 60), # centred block
62+
),
63+
)
64+
def test_bbox_edges(mode: str, box: tuple[int, int, int, int]) -> None:
65+
im = Image.new(mode, (100, 100), 0)
66+
bands = Image.getmodebands(mode)
67+
im.paste(255 if bands == 1 else (255,) * bands, box)
68+
assert im.getbbox() == box
69+
70+
4771
@pytest.mark.parametrize("mode", ("RGBA", "RGBa", "La", "LA", "PA"))
4872
def test_bbox_alpha_only_false(mode: str) -> None:
4973
im = Image.new(mode, (100, 100))

0 commit comments

Comments
 (0)