Skip to content

Fix some warnings from Travis #12316

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 6 commits into from
Sep 29, 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 lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def post_processing(image, dpi):
self._update_methods()

if w > 0 and h > 0:
img = np.fromstring(buffer, np.uint8)
img = np.frombuffer(buffer, np.uint8)
img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255.,
self.dpi)
gc = self.new_gc()
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,10 +1348,9 @@ def get_locator(self, dmin, dmax):
else:
locator = MicrosecondLocator(interval, tz=self.tz)
if dmin.year > 20 and interval < 1000:
_log.warn('Plotting microsecond time intervals is not'
' well supported. Please see the'
' MicrosecondLocator documentation'
' for details.')
_log.warning('Plotting microsecond time intervals is not well '
'supported. Please see the MicrosecondLocator '
'documentation for details.')

locator.set_axis(self.axis)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,9 +1460,9 @@ def pil_to_array(pilImage):
# return MxN luminance array of uint16
raw = pilImage.tobytes('raw', pilImage.mode)
if pilImage.mode.endswith('B'):
x = np.fromstring(raw, '>u2')
x = np.frombuffer(raw, '>u2')
else:
x = np.fromstring(raw, '<u2')
x = np.frombuffer(raw, '<u2')
return x.reshape(pilImage.size[::-1]).astype('=u2')
else: # try to convert to an rgba image
try:
Expand Down
22 changes: 16 additions & 6 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,25 @@ def _xfail_if_format_is_uncomparable(extension):

def _mark_xfail_if_format_is_uncomparable(extension):
if isinstance(extension, str):
will_fail = extension not in comparable_formats()
name = extension
marks = []
elif isinstance(extension, tuple):
# Extension might be a pytest ParameterSet instead of a plain string.
# Unfortunately, this type is not exposed, so since it's a namedtuple,
# check for a tuple instead.
name = extension.values[0]
marks = list(extension.marks)
else:
# Extension might be a pytest marker instead of a plain string.
will_fail = extension.args[0] not in comparable_formats()
if will_fail:
fail_msg = 'Cannot compare %s files on this system' % extension
name = extension.args[0]
marks = [extension.mark]

if name not in comparable_formats():
fail_msg = 'Cannot compare %s files on this system' % (name, )
import pytest
return pytest.mark.xfail(extension, reason=fail_msg, strict=False,
raises=ImageComparisonFailure)
marks += [pytest.mark.xfail(reason=fail_msg, strict=False,
raises=ImageComparisonFailure)]
return pytest.param(name, marks=marks)
else:
return extension

Expand Down
9 changes: 6 additions & 3 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import tempfile
import warnings

import numpy as np
import pytest
Expand All @@ -14,9 +15,11 @@
_determinism_check)


needs_usetex = pytest.mark.skipif(
not checkdep_usetex(True),
reason="This test needs a TeX installation")
with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not checkdep_usetex(True),
reason="This test needs a TeX installation")


@image_comparison(baseline_images=['pdf_use14corefonts'],
Expand Down
15 changes: 9 additions & 6 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import re
import tempfile
import warnings

import pytest

Expand All @@ -14,12 +15,14 @@
_determinism_check)


needs_ghostscript = pytest.mark.skipif(
matplotlib.checkdep_ghostscript()[0] is None,
reason="This test needs a ghostscript installation")
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")
with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_ghostscript = pytest.mark.skipif(
matplotlib.checkdep_ghostscript()[0] is None,
reason="This test needs a ghostscript installation")
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")


# This tests tends to hit a TeX cache lock on AppVeyor.
Expand Down
9 changes: 6 additions & 3 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from io import BytesIO
import os
import tempfile
import warnings
import xml.parsers.expat

import pytest
Expand All @@ -12,9 +13,11 @@
from matplotlib import dviread


needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")
with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")


def test_visibility():
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_single_minus_sign():

buff = io.BytesIO()
plt.savefig(buff, format="rgba", dpi=1000)
array = np.fromstring(buff.getvalue(), dtype=np.uint8)
array = np.frombuffer(buff.getvalue(), dtype=np.uint8)

# If this fails, it would be all white
assert not np.all(array == 0xff)
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_simplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_start_with_moveto():
AABHqP//ej8AAD6z//+FPwAANb7//48/AAAsyf//lz8AACPU//+ePwAAGt///6M/AAAR6v//pj8A
AAj1//+nPwAA/////w=="""

verts = np.fromstring(base64.decodebytes(data), dtype='<i4')
verts = np.frombuffer(base64.decodebytes(data), dtype='<i4')
verts = verts.reshape((len(verts) // 2, 2))
path = Path(verts)
segs = path.iter_segments(transforms.IdentityTransform(),
Expand Down
12 changes: 7 additions & 5 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from matplotlib.testing.decorators import image_comparison


needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")
with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")


@image_comparison(baseline_images=['font_styles'])
Expand Down Expand Up @@ -134,8 +136,8 @@ def test_multiline2():
ax.set_xlim([0, 1.4])
ax.set_ylim([0, 2])
ax.axhline(0.5, color='C2', linewidth=0.3)
sts = ['Line', '2 Lineg\n 2 Lg', '$\sum_i x $', 'hi $\sum_i x $\ntest',
'test\n $\sum_i x $', '$\sum_i x $\n $\sum_i x $']
sts = ['Line', '2 Lineg\n 2 Lg', '$\\sum_i x $', 'hi $\\sum_i x $\ntest',
'test\n $\\sum_i x $', '$\\sum_i x $\n $\\sum_i x $']
renderer = fig.canvas.get_renderer()

def draw_box(ax, tt):
Expand Down
12 changes: 10 additions & 2 deletions lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import warnings

import pytest

import matplotlib
from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt


@pytest.mark.skipif(not matplotlib.checkdep_usetex(True),
reason='Missing TeX or Ghostscript or dvipng')
with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason='Missing TeX of Ghostscript or dvipng')


@needs_usetex
@image_comparison(baseline_images=['test_usetex'],
extensions=['pdf', 'png'],
tol=0.3)
Expand Down
7 changes: 4 additions & 3 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ def test_lines3d():


# Reason for flakiness of SVG test is still unknown.
@image_comparison(baseline_images=['mixedsubplot'], remove_text=True,
extensions=['png', 'pdf',
pytest.mark.xfail('svg', strict=False)])
@image_comparison(
baseline_images=['mixedsubplot'], remove_text=True,
extensions=['png', 'pdf',
pytest.param('svg', marks=pytest.mark.xfail(strict=False))])
def test_mixedsubplots():
def f(t):
s1 = np.cos(2*np.pi*t)
Expand Down