diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 82d0f5cc4580..7c1ad85bc5c7 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1472,6 +1472,7 @@ def tk_window_focus(): default_test_modules = [ 'matplotlib.tests.test_agg', + 'matplotlib.tests.test_afm', 'matplotlib.tests.test_animation', 'matplotlib.tests.test_arrow_patches', 'matplotlib.tests.test_artist', diff --git a/lib/matplotlib/afm.py b/lib/matplotlib/afm.py index 212d6ebe129d..45549e31a28d 100644 --- a/lib/matplotlib/afm.py +++ b/lib/matplotlib/afm.py @@ -57,12 +57,12 @@ def _to_int(x): return int(float(x)) + _to_float = float -if six.PY3: - def _to_str(x): - return x.decode('utf8') -else: - _to_str = str + + +def _to_str(x): + return x.decode('utf8') def _to_list_of_ints(s): diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py new file mode 100644 index 000000000000..ca8583d542be --- /dev/null +++ b/lib/matplotlib/tests/test_afm.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import matplotlib.afm as afm + + +def test_nonascii_str(): + # This tests that we also decode bytes as utf-8 properly. + # Else, font files with non ascii characters fail to load. + inp_str = "привет" + byte_str = inp_str.encode("utf8") + + ret = afm._to_str(byte_str) + assert ret == inp_str