Skip to content

Py3fication of unicode. #10724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/misc/multipage_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# We can also set the file's metadata via the PdfPages object:
d = pdf.infodict()
d['Title'] = 'Multipage PDF Example'
d['Author'] = u'Jouni K. Sepp\xe4nen'
d['Author'] = 'Jouni K. Sepp\xe4nen'
d['Subject'] = 'How to create a multipage pdf file and set its metadata'
d['Keywords'] = 'PdfPages multipage keywords author title subject'
d['CreationDate'] = datetime.datetime(2009, 11, 13)
Expand Down
3 changes: 2 additions & 1 deletion examples/pyplots/text_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

Plotting text of many different kinds.
"""

import matplotlib.pyplot as plt

fig = plt.figure()
Expand All @@ -22,7 +23,7 @@

ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15)

ax.text(3, 2, u'unicode: Institut f\374r Festk\366rperphysik')
ax.text(3, 2, 'unicode: Institut f\374r Festk\366rperphysik')

ax.text(0.95, 0.01, 'colored text in axes coords',
verticalalignment='bottom', horizontalalignment='right',
Expand Down
18 changes: 8 additions & 10 deletions lib/matplotlib/sphinxext/tests/tinypages/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# tinypages documentation build configuration file, created by
# sphinx-quickstart on Tue Mar 18 11:58:34 2014.
#
Expand Down Expand Up @@ -46,8 +44,8 @@
master_doc = 'index'

# General information about the project.
project = u'tinypages'
copyright = u'2014, Matplotlib developers'
project = 'tinypages'
copyright = '2014, Matplotlib developers'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -202,8 +200,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'tinypages.tex', u'tinypages Documentation',
u'Matplotlib developers', 'manual'),
('index', 'tinypages.tex', 'tinypages Documentation',
'Matplotlib developers', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -232,8 +230,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'tinypages', u'tinypages Documentation',
[u'Matplotlib developers'], 1)
('index', 'tinypages', 'tinypages Documentation',
['Matplotlib developers'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -246,8 +244,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'tinypages', u'tinypages Documentation',
u'Matplotlib developers', 'tinypages', 'One line description of project.',
('index', 'tinypages', 'tinypages Documentation',
'Matplotlib developers', 'tinypages', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
56 changes: 23 additions & 33 deletions lib/matplotlib/testing/determinism.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
Provides utilities to test output reproducibility.
"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

import io
import os
import re
import subprocess
import sys
from subprocess import check_output

import pytest

Expand All @@ -34,11 +29,11 @@ def _determinism_save(objects='mhi', format="pdf", usetex=False):
# use different markers...
ax1 = fig.add_subplot(1, 6, 1)
x = range(10)
ax1.plot(x, [1] * 10, marker=u'D')
ax1.plot(x, [2] * 10, marker=u'x')
ax1.plot(x, [3] * 10, marker=u'^')
ax1.plot(x, [4] * 10, marker=u'H')
ax1.plot(x, [5] * 10, marker=u'v')
ax1.plot(x, [1] * 10, marker='D')
ax1.plot(x, [2] * 10, marker='x')
ax1.plot(x, [3] * 10, marker='^')
ax1.plot(x, [4] * 10, marker='H')
ax1.plot(x, [5] * 10, marker='v')

if 'h' in objects:
# also use different hatch patterns
Expand All @@ -63,13 +58,8 @@ def _determinism_save(objects='mhi', format="pdf", usetex=False):
x = range(5)
fig.add_subplot(1, 6, 6).plot(x, x)

if six.PY2 and format == 'ps':
stdout = io.StringIO()
else:
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
fig.savefig(stdout, format=format)
if six.PY2 and format == 'ps':
sys.stdout.write(stdout.getvalue())

# Restores SOURCE_DATE_EPOCH
if sde is None:
Expand All @@ -94,14 +84,14 @@ def _determinism_check(objects='mhi', format="pdf", usetex=False):
"""
plots = []
for i in range(3):
result = check_output([sys.executable, '-R', '-c',
'import matplotlib; '
'matplotlib._called_from_pytest = True; '
'matplotlib.use(%r); '
'from matplotlib.testing.determinism '
'import _determinism_save;'
'_determinism_save(%r,%r,%r)'
% (format, objects, format, usetex)])
result = subprocess.check_output([
sys.executable, '-R', '-c',
'import matplotlib; '
'matplotlib._called_from_pytest = True; '
'matplotlib.use(%r); '
'from matplotlib.testing.determinism import _determinism_save;'
'_determinism_save(%r, %r, %r)'
% (format, objects, format, usetex)])
plots.append(result)
for p in plots[1:]:
if usetex:
Expand All @@ -128,14 +118,14 @@ def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
a string to look at when searching for the timestamp in the document
(used in case the test fails).
"""
buff = check_output([sys.executable, '-R', '-c',
'import matplotlib; '
'matplotlib._called_from_pytest = True; '
'matplotlib.use(%r); '
'from matplotlib.testing.determinism '
'import _determinism_save;'
'_determinism_save(%r,%r)'
% (format, "", format)])
buff = subprocess.check_output([
sys.executable, '-R', '-c',
'import matplotlib; '
'matplotlib._called_from_pytest = True; '
'matplotlib.use(%r); '
'from matplotlib.testing.determinism import _determinism_save;'
'_determinism_save(%r, %r)'
% (format, "", format)])
find_keyword = re.compile(b".*" + keyword + b".*")
key = find_keyword.search(buff)
if key:
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/tests/test_afm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function
from six import BytesIO
from io import BytesIO

import matplotlib.afm as afm

Expand Down Expand Up @@ -33,7 +30,7 @@
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 = u"привет"
inp_str = "привет"
byte_str = inp_str.encode("utf8")

ret = afm._to_str(byte_str)
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import, division, print_function

import six

import sys
import tempfile

Expand Down Expand Up @@ -205,14 +201,14 @@ def test_movie_writer_registry():
assert len(animation.writers._registered) > 0
animation.writers.list() # resets dirty state
assert not animation.writers._dirty
mpl.rcParams['animation.ffmpeg_path'] = u"not_available_ever_xxxx"
mpl.rcParams['animation.ffmpeg_path'] = "not_available_ever_xxxx"
assert animation.writers._dirty
animation.writers.list() # resets
assert not animation.writers._dirty
assert not animation.writers.is_available("ffmpeg")
# something which is guaranteed to be available in path
# and exits immediately
bin = u"true" if sys.platform != 'win32' else u"where"
bin = "true" if sys.platform != 'win32' else "where"
mpl.rcParams['animation.ffmpeg_path'] = bin
assert animation.writers._dirty
animation.writers.list() # resets
Expand Down
5 changes: 1 addition & 4 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- encoding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import os
import shutil
import subprocess
Expand Down Expand Up @@ -73,7 +70,7 @@ def create_figure():

# text and typesetting
plt.plot([0.9], [0.5], "ro", markersize=3)
plt.text(0.9, 0.5, u'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)',
plt.text(0.9, 0.5, 'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)',
ha='right', fontsize=20)
plt.ylabel('sans-serif, blue, $\\frac{\\sqrt{x}}{y^2}$..',
family='sans-serif', color='blue')
Expand Down
64 changes: 25 additions & 39 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function

import io
import re

import numpy as np
import pytest
import six

import matplotlib
import matplotlib.pyplot as plt
Expand All @@ -31,13 +26,14 @@
@pytest.mark.flaky(reruns=3)
@pytest.mark.parametrize('format, use_log, rcParams', [
('ps', False, {}),
needs_ghostscript(('ps', False, {'ps.usedistiller': 'ghostscript'})),
needs_usetex(needs_ghostscript(('ps', False, {'text.latex.unicode': True,
'text.usetex': True}))),
needs_ghostscript(
('ps', False, {'ps.usedistiller': 'ghostscript'})),
needs_usetex(needs_ghostscript(
('ps', False, {'text.latex.unicode': True, 'text.usetex': True}))),
('eps', False, {}),
('eps', True, {'ps.useafm': True}),
needs_usetex(needs_ghostscript(('eps', False, {'text.latex.unicode': True,
'text.usetex': True}))),
needs_usetex(needs_ghostscript(
('eps', False, {'text.latex.unicode': True, 'text.usetex': True}))),
], ids=[
'ps',
'ps with distiller',
Expand All @@ -50,35 +46,25 @@ def test_savefig_to_stringio(format, use_log, rcParams):
matplotlib.rcParams.update(rcParams)

fig, ax = plt.subplots()
buffers = [
six.moves.StringIO(),
io.StringIO(),
io.BytesIO()]

if use_log:
ax.set_yscale('log')

ax.plot([1, 2], [1, 2])
ax.set_title(u"Déjà vu")
for buffer in buffers:
fig.savefig(buffer, format=format)

values = [x.getvalue() for x in buffers]

if six.PY3:
values = [
values[0].encode('ascii'),
values[1].encode('ascii'),
values[2]]

# Remove comments from the output. This includes things that
# could change from run to run, such as the time.
values = [re.sub(b'%%.*?\n', b'', x) for x in values]

assert values[0] == values[1]
assert values[1] == values[2].replace(b'\r\n', b'\n')
for buffer in buffers:
buffer.close()

with io.StringIO() as s_buf, io.BytesIO() as b_buf:

if use_log:
ax.set_yscale('log')

ax.plot([1, 2], [1, 2])
ax.set_title("Déjà vu")
fig.savefig(s_buf, format=format)
fig.savefig(b_buf, format=format)

s_val = s_buf.getvalue().encode('ascii')
b_val = b_buf.getvalue()

# Remove comments from the output. This includes things that could
# change from run to run, such as the time.
s_val, b_val = [re.sub(b'%%.*?\n', b'', x) for x in [s_val, b_val]]

assert s_val == b_val.replace(b'\r\n', b'\n')


def test_patheffects():
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_various_labels():
fig = plt.figure()
ax = fig.add_subplot(121)
ax.plot(np.arange(4), 'o', label=1)
ax.plot(np.linspace(4, 4.1), 'o', label=u'D\xe9velopp\xe9s')
ax.plot(np.linspace(4, 4.1), 'o', label='Développés')
ax.plot(np.arange(4, 1, -1), 'o', label='__nolegend__')
ax.legend(numpoints=1, loc=0)

Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from __future__ import absolute_import, division, print_function
import warnings

from numpy.testing import assert_almost_equal
import numpy as np
from numpy.testing import assert_almost_equal
import pytest

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

import warnings


class TestMaxNLocator(object):
basic_data = [
Expand Down Expand Up @@ -578,7 +576,7 @@ class TestEngFormatter(object):
(-0.0, ('0', '0', '0.00')),
(-0, ('0', '0', '0.00')),
(0, ('0', '0', '0.00')),
(1.23456789e-6, (u'1.23457 \u03bc', u'1 \u03bc', u'1.23 \u03bc')),
(1.23456789e-6, ('1.23457 \u03bc', '1 \u03bc', '1.23 \u03bc')),
(0.123456789, ('123.457 m', '123 m', '123.46 m')),
(0.1, ('100 m', '100 m', '100.00 m')),
(1, ('1', '1', '1.00')),
Expand Down
Loading