Skip to content

Commit b187215

Browse files
committed
Add test for invalid PDF metadata warnings.
1 parent f78133e commit b187215

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ def test_savefig_metadata(monkeypatch):
161161
}
162162

163163

164+
def test_invalid_metadata():
165+
fig, ax = plt.subplots()
166+
167+
with pytest.warns(UserWarning,
168+
match="Unknown infodict keyword: 'foobar'."):
169+
fig.savefig(io.BytesIO(), format='pdf', metadata={'foobar': 'invalid'})
170+
171+
with pytest.warns(UserWarning,
172+
match='not an instance of datetime.datetime.'):
173+
fig.savefig(io.BytesIO(), format='pdf',
174+
metadata={'ModDate': '1968-08-01'})
175+
176+
with pytest.warns(UserWarning,
177+
match='not one of {"True", "False", "Unknown"}'):
178+
fig.savefig(io.BytesIO(), format='pdf', metadata={'Trapped': 'foo'})
179+
180+
with pytest.warns(UserWarning, match='not an instance of str.'):
181+
fig.savefig(io.BytesIO(), format='pdf', metadata={'Title': 1234})
182+
183+
164184
def test_multipage_metadata(monkeypatch):
165185
pikepdf = pytest.importorskip('pikepdf')
166186
monkeypatch.setenv('SOURCE_DATE_EPOCH', '0')

0 commit comments

Comments
 (0)