Skip to content

Commit 3d1d30f

Browse files
committed
Merge pull request mwaskom#270 from mwaskom/fix_tests
Make rc tests passable on systems without MS fonts
2 parents 3f7770e + 6fb5b2b commit 3d1d30f

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

seaborn/tests/test_rcmod.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,17 @@ def test_set_font(self):
173173
_, ax = plt.subplots()
174174
ax.set_xlabel("foo")
175175

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")
181187

182188
def test_set_serif_font(self):
183189

@@ -204,8 +210,37 @@ def test_different_sans_serif(self):
204210
_, ax = plt.subplots()
205211
ax.set_xlabel("foo")
206212

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

Comments
 (0)