8000 Convert test_s* files to pytest and flake8 them by QuLogic · Pull Request #7918 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Convert test_s* files to pytest and flake8 them #7918

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 2 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Cleanup test_s* files for PEP8.
  • Loading branch information
QuLogic committed Jan 22, 2017
commit 72807ab126af374637c5abcb3e8fb5d5fc29520b
3 changes: 0 additions & 3 deletions lib/matplotlib/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ def test_pep8_conformance_installed_files():
'tests/test_lines.py',
'tests/test_mathtext.py',
'tests/test_rcparams.py',
'tests/test_simplification.py',
'tests/test_streamplot.py',
'tests/test_subplots.py',
'tests/test_tightlayout.py',
'tests/test_triangulation.py',
'backends/backend_agg.py',
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/tests/test_sankey.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

from matplotlib.sankey import Sankey
from matplotlib.testing.decorators import cleanup

Expand Down
88 changes: 45 additions & 43 deletions lib/matplotlib/tests/test_simplification.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six
import io

import numpy as np
import matplotlib
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
import matplotlib.pyplot as plt
import pytest

from matplotlib import patches, path, transforms
from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt

import pytest
import io
from matplotlib import patches, transforms
from matplotlib.path import Path

nan = np.nan
Path = path.Path

# NOTE: All of these tests assume that path.simplify is set to True
# (the default)
Expand All @@ -24,39 +21,38 @@ def test_clipping():
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.plot(t, s, linewidth=1.0)
ax.set_ylim((-0.20, -0.28))


@image_comparison(baseline_images=['overflow'], remove_text=True)
def test_overflow():
x = np.array([1.0,2.0,3.0,2.0e5])
x = np.array([1.0, 2.0, 3.0, 2.0e5])
y = np.arange(len(x))

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)
ax.set_xlim(xmin=2,xmax=6)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlim(xmin=2, xmax=6)


@image_comparison(baseline_images=['clipping_diamond'], remove_text=True)
def test_diamond():
x = np.array([0.0, 1.0, 0.0, -1.0, 0.0])
y = np.array([1.0, 0.0, -1.0, 0.0, 1.0])

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlim(xmin=-0.6, xmax=0.6)
ax.set_ylim(ymin=-0.6, ymax=0.6)


@cleanup
def test_noise():
np.random.seed(0)
x = np.random.uniform(size=(5000,)) * 50

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)

path = p1[0].get_path()
Expand All @@ -66,13 +62,14 @@ def test_noise():

assert len(simplified) == 3884


@cleanup
def test_sine_plus_noise():
np.random.seed(0)
x = np.sin(np.linspace(0, np.pi * 2.0, 1000)) + np.random.uniform(size=(1000,)) * 0.01
x = (np.sin(np.linspace(0, np.pi * 2.0, 1000)) +
np.random.uniform(size=(1000,)) * 0.01)

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)

path = p1[0].get_path()
Expand All @@ -82,32 +79,34 @@ def test_sine_plus_noise():

< 10000 /td>
assert len(simplified) == 876


@image_comparison(baseline_images=['simplify_curve'], remove_text=True)
def test_simplify_curve():
pp1 = patches.PathPatch(
Path([(0, 0), (1, 0), (1, 1), (nan, 1), (0, 0), (2, 0), (2, 2), (0, 0)],
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
Path([(0, 0), (1, 0), (1, 1), (np.nan, 1), (0, 0), (2, 0), (2, 2),
(0, 0)],
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3,
Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
fc="none")

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.add_patch(pp1)
ax.set_xlim((0, 2))
ax.set_ylim((0, 2))


@image_comparison(baseline_images=['hatch_simplify'], remove_text=True)
def test_hatch():
fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.add_patch(plt.Rectangle((0, 0), 1, 1, fill=False, hatch="/"))
ax.set_xlim((0.45, 0.55))
ax.set_ylim((0.45, 0.55))


@image_comparison(baseline_images=['fft_peaks'], remove_text=True)
def test_fft_peaks():
fig = plt.figure()
fig, ax = plt.subplots()
t = np.arange(65536)
ax = fig.add_subplot(111)
p1 = ax.plot(abs(np.fft.fft(np.sin(2*np.pi*.01*t)*np.blackman(len(t)))))

path = p1[0].get_path()
Expand All @@ -117,6 +116,7 @@ def test_fft_peaks():

assert len(simplified) == 20


@cleanup
def test_start_with_moveto():
# Should be entirely clipped away to a single MOVETO
Expand Down Expand Up @@ -153,19 +153,21 @@ def test_start_with_moveto():
verts = np.fromstring(decodebytes(data), dtype='<i4')
verts = verts.reshape((len(verts) // 2, 2))
path = Path(verts)
segs = path.iter_segments(transforms.IdentityTransform(), clip=(0.0, 0.0, 100.0, 100.0))
segs = path.iter_segments(transforms.IdentityTransform(),
clip=(0.0, 0.0, 100.0, 100.0))
segs = list(segs)
assert len(segs) == 1
assert segs[0][1] == Path.MOVETO


@cleanup
def test_throw_rendering_complexity_exceeded():
plt.rcParams['path.simplify'] = False
xx = np.arange(200000)
yy = np.random.rand(200000)
yy[1000] = np.nan
fig = plt.figure()
ax = fig.add_subplot(111)

fig, ax = plt.subplots()
ax.plot(xx, yy)
with pytest.raises(OverflowError):
fig.savefig(io.BytesIO())
Expand All @@ -175,9 +177,9 @@ def test_throw_rendering_complexity_exceeded():
def test_clipper():
dat = (0, 1, 0, 2, 0, 3, 0, 4, 0, 5)
fig = plt.figure(figsize=(2, 1))
fig.subplots_adjust(left = 0, bottom = 0, wspace = 0, hspace = 0)
fig.subplots_adjust(left=0, bottom=0, wspace=0, hspace=0)

ax = fig.add_axes((0, 0, 1.0, 1.0), ylim = (0, 5), autoscale_on = False)
ax = fig.add_axes((0, 0, 1.0, 1.0), ylim=(0, 5), autoscale_on=False)
ax.plot(dat)
ax.xaxis.set_major_locator(plt.MultipleLocator(1))
ax.yaxis.set_major_locator(plt.MultipleLocator(1))
Expand All @@ -186,39 +188,39 @@ def test_clipper():

ax.set_xlim(5, 9)


@image_comparison(baseline_images=['para_equal_perp'], remove_text=True)
def test_para_equal_perp():
x = np.array([0, 1, 2, 1, 0, -1, 0, 1] + [1] * 128)
y = np.array([1, 1, 2, 1, 0, -1, 0, 0] + [0] * 128)

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.plot(x + 1, y + 1)
ax.plot(x + 1, y + 1, 'ro')


@image_comparison(baseline_images=['clipping_with_nans'])
def test_clipping_with_nans():
x = np.linspace(0, 3.14 * 2, 3000)
y = np.sin(x)
x[::100] = np.nan

fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_ylim(-0.25, 0.25)


def test_clipping_full():
p = path.Path([[1e30, 1e30]] * 5)
p = Path([[1e30, 1e30]] * 5)
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
assert simplified == []

p = path.Path([[50, 40], [75, 65]], [1, 2])
p = Path([[50, 40], [75, 65]], [1, 2])
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
assert ([(list(x), y) for x, y in simplified] ==
[([50, 40], 1), ([75, 65], 2)])

p = path.Path([[50, 40]], [1])
p = Path([[50, 40]], [1])
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
assert ([(list(x), y) for x, y in simplified] ==
[([50, 40], 1)])
3 changes: 0 additions & 3 deletions lib/matplotlib/tests/test_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
unicode_literals)

import numpy as np
import six

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from matplotlib.testing.decorators import image_comparison, cleanup


Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_streamplot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

import numpy as np
from numpy.testing import assert_array_almost_equal
import matplotlib.pyplot as plt
Expand All @@ -16,6 +14,7 @@ def velocity_field():
V = 1 + X - Y**2
return X, Y, U, V


def swirl_velocity_field():
x = np.linspace(-3., 3., 100)
y = np.linspace(-3., 3., 100)
Expand All @@ -25,6 +24,7 @@ def swirl_velocity_field():
V = np.sin(a) * (-Y) + np.cos(a) * X
return x, y, U, V


@image_comparison(baseline_images=['streamplot_startpoints'])
def test_startpoints():
X, Y, U, V = velocity_field()
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
unicode_literals)

import warnings
import six
from six.moves import xrange

import numpy
import matplotlib.pyplot as plt
Expand All @@ -30,7 +28,9 @@ def check_shared(axs, x_shared, y_shared):


def check_visible(axs, x_visible, y_visible):
tostr = lambda v: "invisible" if v else "visible"
def tostr(v):
return "invisible" if v else "visible"

for (ax, vx, vy) in zip(axs, x_visible, y_visible):
for l in ax.get_xticklabels() + [ax.get_xaxis().offsetText]:
assert l.get_visible() == vx, \
Expand Down
0