| 157 | |
| 158 | |
| 159 | def test_ft2font_invalid_args(tmp_path): |
| 160 | # filename argument. |
| 161 | with pytest.raises(TypeError, match='to a font file or a binary-mode file object'): |
| 162 | ft2font.FT2Font(None) |
| 163 | with pytest.raises(TypeError, match='to a font file or a binary-mode file object'): |
| 164 | ft2font.FT2Font(object()) # Not bytes or string, and has no read() method. |
| 165 | file = tmp_path / 'invalid-font.ttf' |
| 166 | file.write_text('This is not a valid font file.') |
| 167 | with (pytest.raises(TypeError, match='to a font file or a binary-mode file object'), |
| 168 | file.open('rt') as fd): |
| 169 | ft2font.FT2Font(fd) |
| 170 | with (pytest.raises(TypeError, match='to a font file or a binary-mode file object'), |
| 171 | file.open('wt') as fd): |
| 172 | ft2font.FT2Font(fd) |
| 173 | with (pytest.raises(TypeError, match='to a font file or a binary-mode file object'), |
| 174 | file.open('wb') as fd): |
| 175 | ft2font.FT2Font(fd) |
| 176 | |
| 177 | file = fm.findfont('DejaVu Sans') |
| 178 | |
| 179 | # hinting_factor argument. |
| 180 | with pytest.raises(TypeError, match='incompatible constructor arguments'): |
| 181 | ft2font.FT2Font(file, 1.3) |
| 182 | with pytest.warns(mpl.MatplotlibDeprecationWarning, |
| 183 | match='text.hinting_factor rcParam was deprecated .+ 3.11'): |
| 184 | mpl.rcParams['text.hinting_factor'] = 8 |
| 185 | with pytest.warns(mpl.MatplotlibDeprecationWarning, |
| 186 | match='The hinting_factor parameter was deprecated'): |
| 187 | ft2font.FT2Font(file, 0) |
| 188 | |
| 189 | with pytest.raises(TypeError, match='incompatible constructor arguments'): |
| 190 | # failing to be a list will fail before the 0 |
| 191 | ft2font.FT2Font(file, _fallback_list=(0,)) |
| 192 | with pytest.raises(TypeError, match='incompatible constructor arguments'): |
| 193 | ft2font.FT2Font(file, _fallback_list=[0]) |
| 194 | |
| 195 | # kerning_factor argument. |
| 196 | with pytest.raises(TypeError, match='incompatible constructor arguments'): |
| 197 | ft2font.FT2Font(file, _kerning_factor=1.3) |
| 198 | with pytest.warns(mpl.MatplotlibDeprecationWarning, |
| 199 | match='text.kerning_factor rcParam was deprecated .+ 3.11'): |
| 200 | mpl.rcParams['text.kerning_factor'] = 0 |
| 201 | with pytest.warns(mpl.MatplotlibDeprecationWarning, |
| 202 | match='_kerning_factor parameter was deprecated .+ 3.11'): |
| 203 | ft2font.FT2Font(file, _kerning_factor=123) |
| 204 | |
| 205 | |
| 206 | @pytest.mark.parametrize('name, size, skippable', |