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 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
8 changes: 0 additions & 8 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,14 +1502,6 @@ def _jupyter_nbextension_paths():
'matplotlib.tests.test_pickle',
'matplotlib.tests.test_png',
'matplotlib.tests.test_quiver',
'matplotlib.tests.test_sankey',
'matplotlib.tests.test_scale',
'matplotlib.tests.test_simplification',
'matplotlib.tests.test_skew',
'matplotlib.tests.test_spines',
'matplotlib.tests.test_streamplot',
'matplotlib.tests.test_style',
'matplotlib.tests.test_subplots',
'matplotlib.tests.test_text',
'matplotlib.tests.test_texmanager',
'matplotlib.tests.test_type1font',
Expand Down
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
7 changes: 0 additions & 7 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 All @@ -12,8 +10,3 @@ def test_sankey():
# lets just create a sankey instance and check the code runs
sankey = Sankey()
sankey.add()


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
5 changes: 0 additions & 5 deletions lib/matplotlib/tests/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,3 @@ def test_log_scatter():

buf = io.BytesIO()
fig.savefig(buf, format='svg')


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
99 changes: 47 additions & 52 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 pytest

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

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

from nose.tools import raises
import io

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():

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,33 +153,33 @@ 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
@raises(OverflowError)
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)
try:
with pytest.raises(OverflowError):
fig.savefig(io.BytesIO())
finally:
plt.rcParams['path.simplify'] = True


@image_comparison(baseline_images=['clipper_edge'], remove_text=True)
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 @@ -188,44 +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)])


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
4 changes: 0 additions & 4 deletions lib/matplotlib/tests/test_skew.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,3 @@ def test_skew_rectange():
alpha=0.5, facecolor='coral'))

plt.subplots_adjust(wspace=0, left=0, right=1, bottom=0)

if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
12 changes: 4 additions & 8 deletions lib/matplotlib/tests/test_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
unicode_literals)

import numpy as np
from nose.tools import assert_true, assert_less
import six

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


Expand Down Expand Up @@ -71,11 +67,11 @@ def test_label_without_ticks():
spine = ax.spines['left']
spinebbox = spine.get_transform().transform_path(
spine.get_path()).get_extents()
assert_less(ax.yaxis.label.get_position()[0], spinebbox.xmin,
"Y-Axis label not left of the spine")
assert ax.yaxis.label.get_position()[0] < spinebbox.xmin, \
"Y-Axis label not left of the spine"

spine = ax.spines['bottom']
spinebbox = spine.get_transform().transform_path(
spine.get_path()).get_extents()
assert_less(ax.xaxis.label.get_position()[1], spinebbox.ymin,
"X-Axis label not below the spine")
assert ax.xaxis.label.get_position()[1] < spinebbox.ymin, \
"X-Axis label not below the spine"
9 changes: 2 additions & 7 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 Expand Up @@ -95,8 +95,3 @@ def test_streamplot_limits():
# datalim.
assert_array_almost_equal(ax.dataLim.bounds, (20, 30, 15, 6),
decimal=1)


if __name__=='__main__':
import nose
nose.runmodule()
14 changes: 5 additions & 9 deletions lib/matplotlib/tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from collections import OrderedDict
from contextlib import contextmanager

from nose.tools import assert_raises
from nose.plugins.attrib import attr
import pytest

import matplotlib as mpl
from matplotlib import style
Expand Down Expand Up @@ -70,7 +69,7 @@ def test_use():
assert mpl.rcParams[PARAM] == VALUE


@attr('network')
@pytest.mark.network
def test_use_url():
with temp_style('test', DUMMY_SETTINGS):
with style.context('https://gist.github.com/adrn/6590261/raw'):
Expand Down Expand Up @@ -140,10 +139,7 @@ def test_context_with_badparam():
with style.context({PARAM: other_value}):
assert mpl.rcParams[PARAM] == other_value
x = style.context([d])
assert_raises(KeyError, x.__enter__)
with pytest.raises(KeyError):
with x:
pass
assert mpl.rcParams[PARAM] == other_value


if __name__ == '__main__':
from numpy import testing
testing.run_module_suite()
Loading
0