8000 TST: Add a test for FT2Image · matplotlib/matplotlib@2c3cae2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c3cae2

Browse files
committed
TST: Add a test for FT2Image
The only externally-available API here is `draw_rect_filled` and conversion to NumPy arrays via the buffer protocol.
1 parent b01462c commit 2c3cae2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/matplotlib/tests/test_ft2font.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from pathlib import Path
1+
import itertools
22
import io
3+
from pathlib import Path
34

5+
import numpy as np
46
import pytest
57

68
from matplotlib import ft2font
@@ -9,6 +11,24 @@
911
import matplotlib.pyplot as plt
1012

1113

14+
def test_ft2image_draw_rect_filled():
15+
width = 23
16+
height = 42
17+
for x0, y0, x1, y1 in itertools.product([1, 100], [2, 200], [4, 400], [8, 800]):
18+
im = ft2font.FT2Image(width, height)
19+
im.draw_rect_filled(x0, y0, x1, y1)
20+
a = np.asarray(im)
21+
assert a.dtype == np.uint8
22+
assert a.shape == (height, width)
23+
if x0 == 100 or y0 == 200:
24+
# All the out-of-bounds starts should get automatically clipped.
25+
assert np.sum(a) == 0
26+
else:
27+
# Otherwise, ends are clipped to the dimension, but are also _inclusive_.
28+
filled = (min(x1 + 1, width) - x0) * (min(y1 + 1, height) - y0)
29+
assert np.sum(a) == 255 * filled
30+
31+
1232
def test_fallback_errors():
1333
file_name = fm.findfont('DejaVu Sans')
1434

0 commit comments

Comments
 (0)
0