@@ -173,11 +173,17 @@ def test_set_font(self):
173
173
_ , ax = plt .subplots ()
174
174
ax .set_xlabel ("foo" )
175
175
176
- nt .assert_equal (ax .xaxis .label .get_fontname (),
177
- "Verdana" )
178
-
179
- rcmod .set ()
180
- plt .close ("all" )
176
+ try :
177
+ nt .assert_equal (ax .xaxis .label .get_fontname (),
178
+ "Verdana" )
179
+ except AssertionError :
180
+ if has_verdana :
181
+ raise
182
+ else :
183
+ raise nose .SkipTest ("Verdana font is not present" )
184
+ finally :
185
+ rcmod .set ()
186
+ plt .close ("all" )
181
187
182
188
def test_set_serif_font (self ):
183
189
@@ -204,8 +210,37 @@ def test_different_sans_serif(self):
204
210
_ , ax = plt .subplots ()
205
211
ax .set_xlabel ("foo" )
206
212
207
- nt .assert_equal (ax .xaxis .label .get_fontname (),
208
- "Verdana" )
209
-
210
- rcmod .set ()
211
- plt .close ("all" )
213
+ try :
214
+ nt .assert_equal (ax .xaxis .label .get_fontname (),
215
+ "Verdana" )
216
+ except AssertionError :
217
+ if has_verdana :
218
+ raise
219
+ else :
220
+ raise nose .SkipTest ("Verdana font is not present" )
221
+ finally :
222
+ rcmod .set ()
223
+ plt .close ("all" )
224
+
225
+
226
+ def has_verdana ():
227
+ """Helper to verify if Verdana font is present"""
228
+ # This import is relatively lengthy, so to prevent its import for
229
+ # testing other tests in this module not requiring this knowledge,
230
+ # import font_manager here
231
+ import matplotlib .font_manager as mplfm
232
+ try :
233
+ verdana_font = mplfm .findfont ('Verdana' , fallback_to_default = False )
234
+ except :
235
+ # if https://github.com/matplotlib/matplotlib/pull/3435
236
+ # gets accepted
237
+ return False
238
+ # otherwise check if not matching the logic for a 'default' one
239
+ try :
240
+ unlikely_font = mplfm .findfont ("very_unlikely_to_exist1234" ,
241
+ fallback_to_default = False )
242
+ except :
243
+ # if matched verdana but not unlikely, Verdana must exist
244
+ return True
245
+ # otherwise -- if they match, must be the same default
246
+ return verdana_font != unlikely_font
0 commit comments