Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a1b4498

Browse filesBrowse files
committed
TST: Add tests for invalid FT2Font arguments
1 parent 720aed0 commit a1b4498
Copy full SHA for a1b4498

File tree

Expand file treeCollapse file tree

1 file changed

+29
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-15
lines changed

‎lib/matplotlib/tests/test_ft2font.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ft2font.py
+29-15Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,39 @@ def test_ft2font_stix_bold_attrs():
125125
assert font.bbox == (4, -355, 1185, 2095)
126126

127127

128-
def test_fallback_errors():
129-
file_name = fm.findfont('DejaVu Sans')
128+
def test_ft2font_invalid_args(tmp_path):
129+
# filename argument.
130+
with pytest.raises(TypeError, match='to a font file or a binary-mode file object'):
131+
ft2font.FT2Font(None)
132+
file = tmp_path / 'invalid-font.ttf'
133+
file.write_text('This is not a valid font file.')
134+
with (pytest.raises(TypeError, match='to a font file or a binary-mode file object'),
135+
file.open('rt') as fd):
136+
ft2font.FT2Font(fd)
137+
with (pytest.raises(TypeError, match='to a font file or a binary-mode file object'),
138+
file.open('wt') as fd):
139+
ft2font.FT2Font(fd)
140+
with (pytest.raises(TypeError, match='to a font file or a binary-mode file object'),
141+
file.open('wb') as fd):
142+
ft2font.FT2Font(fd)
130143

131-
with pytest.raises(TypeError, match="Fallback list must be a list"):
132-
# failing to be a list will fail before the 0
133-
ft2font.FT2Font(file_name, _fallback_list=(0,)) # type: ignore[arg-type]
144+
file = fm.findfont('DejaVu Sans')
134145

135-
with pytest.raises(
136-
TypeError, match="Fallback fonts must be FT2Font objects."
137-
):
138-
ft2font.FT2Font(file_name, _fallback_list=[0]) # type: ignore[list-item]
146+
# hinting_factor argument.
147+
with pytest.raises(TypeError, match='cannot be interpreted as an integer'):
148+
ft2font.FT2Font(file, 1.3)
149+
with pytest.raises(ValueError, match='hinting_factor must be greater than 0'):
150+
ft2font.FT2Font(file, 0)
139151

152+
with pytest.raises(TypeError, match='Fallback list must be a list'):
153+
# failing to be a list will fail before the 0
154+
ft2font.FT2Font(file, _fallback_list=(0,)) # type: ignore[arg-type]
155+
with pytest.raises(TypeError, match='Fallback fonts must be FT2Font objects.'):
156+
ft2font.FT2Font(file, _fallback_list=[0]) # type: ignore[list-item]
140157

141-
def test_ft2font_positive_hinting_factor():
142-
file_name = fm.findfont('DejaVu Sans')
143-
with pytest.raises(
144-
ValueError, match="hinting_factor must be greater than 0"
145-
):
146-
ft2font.FT2Font(file_name, 0)
158+
# kerning_factor argument.
159+
with pytest.raises(TypeError, match='cannot be interpreted as an integer'):
160+
ft2font.FT2Font(file, _kerning_factor=1.3)
147161

148162

149163
@pytest.mark.parametrize('family_name, file_name',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.