From ce928591fc9ff6de73defd612b4b16beac24d4d1 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 4 Feb 2017 18:30:33 -0500 Subject: [PATCH 1/6] FIX: always decode bytes as utf-8 in AFM headers closes #3517 --- lib/matplotlib/afm.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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): From 343f5fc4bc1fb8a0d79a30a9b3971a482584f913 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Sat, 11 Mar 2017 12:38:53 -0800 Subject: [PATCH 2/6] TST afm._to_str is now tested against utf8-encoded bytes --- lib/matplotlib/tests/test_afm.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/matplotlib/tests/test_afm.py diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py new file mode 100644 index 000000000000..ae843242d6dc --- /dev/null +++ b/lib/matplotlib/tests/test_afm.py @@ -0,0 +1,13 @@ +import matplotlib.afm as afm +import six + + +def test_nonascii_str(): + # This tests that we also decode bytes as utf-8 properly. + # Else, font files with non ascii caracters fail to load. + + if six.PY3: + string = "привет".encode("utf8") + else: + string = "привет" + afm._to_str(string) From 61758e3ac04f7b1a1766036a3d12611a734b9b8b Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 12 Mar 2017 17:58:08 -0400 Subject: [PATCH 3/6] TST: add future imports --- lib/matplotlib/tests/test_afm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py index ae843242d6dc..3627ef34d25a 100644 --- a/lib/matplotlib/tests/test_afm.py +++ b/lib/matplotlib/tests/test_afm.py @@ -1,3 +1,6 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import matplotlib.afm as afm import six From 7cdab8873a03ed84b8b624bd4ba56b0844e958d0 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 13 Mar 2017 16:03:01 -0400 Subject: [PATCH 4/6] TST: tweak and whitelist test --- lib/matplotlib/__init__.py | 1 + lib/matplotlib/tests/test_afm.py | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) 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/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py index 3627ef34d25a..5b83f6200eff 100644 --- a/lib/matplotlib/tests/test_afm.py +++ b/lib/matplotlib/tests/test_afm.py @@ -8,9 +8,8 @@ def test_nonascii_str(): # This tests that we also decode bytes as utf-8 properly. # Else, font files with non ascii caracters fail to load. + inp_str = "привет" + byte_str = inp_str.encode("utf8") - if six.PY3: - string = "привет".encode("utf8") - else: - string = "привет" - afm._to_str(string) + ret = afm._to_str(byte_str) + assert ret == inp_str From 1667a0c01394ff268aa43412d1174b0cbafed21b Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Sun, 19 Mar 2017 11:59:42 -0700 Subject: [PATCH 5/6] FIX reviewers's comment --- lib/matplotlib/tests/test_afm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py index 5b83f6200eff..35ee47cd006d 100644 --- a/lib/matplotlib/tests/test_afm.py +++ b/lib/matplotlib/tests/test_afm.py @@ -2,12 +2,11 @@ unicode_literals) import matplotlib.afm as afm -import six def test_nonascii_str(): # This tests that we also decode bytes as utf-8 properly. - # Else, font files with non ascii caracters fail to load. + # Else, font files with non ascii characters fail to load. inp_str = "привет" byte_str = inp_str.encode("utf8") From b4a8191cfc47f6b137c9033ea062c6a06458a190 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Sun, 19 Mar 2017 14:16:34 -0700 Subject: [PATCH 6/6] FIX Added encoding comment in test_afm for py2.7 --- lib/matplotlib/tests/test_afm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py index 35ee47cd006d..ca8583d542be 100644 --- a/lib/matplotlib/tests/test_afm.py +++ b/lib/matplotlib/tests/test_afm.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from __future__ import (absolute_import, division, print_function, unicode_literals)