Skip to content

Commit 31c04ad

Browse files
committed
TST: add tests for malformed, but parsable AFM files
1 parent 46f0bec commit 31c04ad

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/matplotlib/tests/test_afm.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from io import BytesIO
22
import pytest
3+
import logging
34

45
from matplotlib import afm
56
from matplotlib import font_manager as fm
@@ -107,3 +108,30 @@ def test_bad_afm(afm_data):
107108
fh = BytesIO(afm_data)
108109
with pytest.raises(RuntimeError):
109110
header = afm._parse_header(fh)
111+
112+
113+
@pytest.mark.parametrize(
114+
"afm_data",
115+
[
116+
b"""StartFontMetrics 2.0
117+
Comment Comments are ignored.
118+
Comment Creation Date:Mon Nov 13 12:34:11 GMT 2017
119+
Aardvark bob
120+
FontName MyFont-Bold
121+
EncodingScheme FontSpecific
122+
StartCharMetrics 3""",
123+
b"""StartFontMetrics 2.0
124+
Comment Comments are ignored.
125+
Comment Creation Date:Mon Nov 13 12:34:11 GMT 2017
126+
ItalicAngle zero degrees
127+
FontName MyFont-Bold
128+
EncodingScheme FontSpecific
129+
StartCharMetrics 3""",
130+
],
131+
)
132+
def test_malformed_header(afm_data, caplog):
133+
fh = BytesIO(afm_data)
134+
with caplog.at_level(logging.ERROR):
135+
header = afm._parse_header(fh)
136+
137+
assert len(caplog.records) == 1

0 commit comments

Comments
 (0)