@@ -125,25 +125,39 @@ def test_ft2font_stix_bold_attrs():
125
125
assert font .bbox == (4 , - 355 , 1185 , 2095 )
126
126
127
127
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 )
130
143
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' )
134
145
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 )
139
151
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]
140
157
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 )
147
161
148
162
149
163
@pytest .mark .parametrize ('family_name, file_name' ,
0 commit comments