10000 All tests starting with a p now PEP8 compliant. · matplotlib/matplotlib@15c8c90 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15c8c90

Browse files
committed
All tests starting with a p now PEP8 compliant.
1 parent e104a0e commit 15c8c90

11 files changed

+128
-119
lines changed

lib/matplotlib/tests/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
from __future__ import print_function
2-
from matplotlib import rcParams, rcdefaults, use
32

43
import difflib
54

5+
from matplotlib import rcParams, rcdefaults, use
6+
67

78
_multiprocess_can_split_ = True
89

910

1011
def setup():
11-
use('Agg', warn=False) # use Agg backend for these tests
12+
use('Agg', warn=False) # use Agg backend for these tests
1213

1314
# These settings *must* be hardcoded for running the comparison
1415
# tests and are not necessarily the default values as specified in
1516
# rcsetup.py
16-
rcdefaults() # Start with all defaults
17+
rcdefaults() # Start with all defaults
1718
rcParams['font.family'] = 'Bitstream Vera Sans'
1819
rcParams['text.hinting'] = False
1920
rcParams['text.hinting_factor'] = 8
2021

2122

2223
def assert_str_equal(reference_str, test_str,
23-
format_str='String {str1} and {str2} do not match:\n{differences}'):
24+
format_str=('String {str1} and {str2} do not '
25+
'match:\n{differences}')):
2426
"""
25-
Assert the two strings are equal. If not, fail and print their diffs using difflib.
27+
Assert the two strings are equal. If not, fail and print their
28+
diffs using difflib.
2629
2730
"""
2831
if reference_str != test_str:

lib/matplotlib/tests/test_animation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ def animate(i):
4848
anim.save(F.name, fps=30, writer=writer)
4949

5050

51-
if __name__ == '__main__':
51+
if __name__ == "__main__":
5252
import nose
53-
nose.runmodule()
53+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# -*- encoding: utf-8 -*-
2+
import io
23

34
from matplotlib import rcParams
45
from matplotlib import pyplot as plt
56
from matplotlib.testing.decorators import image_comparison, knownfailureif
67

8+
79
@image_comparison(baseline_images=['pdf_use14corefonts'], extensions=['pdf'])
810
def test_use14corefonts():
911
rcParams['pdf.use14corefonts'] = True
@@ -24,11 +26,14 @@ def test_use14corefonts():
2426

2527

2628
def test_type42():
27-
import io
28-
2929
rcParams['pdf.fonttype'] = 42
3030

3131
fig = plt.figure()
3232
ax = fig.add_subplot(111)
33-
ax.plot([1,2,3])
33+
ax.plot([1, 2, 3])
3434
fig.savefig(io.BytesIO())
35+
36+
37+
if __name__ == "__main__":
38+
import nose
39+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# -*- encoding: utf-8 -*-
2-
32
import os
43
import shutil
4+
55
import numpy as np
66
import nose
77
from nose.plugins.skip import SkipTest
8+
89
import matplotlib as mpl
910
import matplotlib.pyplot as plt
1011
from matplotlib.compat import subprocess
1112
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1213
from matplotlib.testing.decorators import _image_directories
1314

15+
1416
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
1517

1618

@@ -59,18 +61,20 @@ def compare_figure(fname):
5961
shutil.copyfile(os.path.join(baseline_dir, fname), expected)
6062
err = compare_images(expected, actual, tol=14)
6163
if err:
62-
raise ImageComparisonFailure('images not close: %s vs. %s' % (actual, expected))
64+
raise ImageComparisonFailure('images not close: %s vs. '
65+
'%s' % (actual, expected))
6366

64-
###############################################################################
6567

6668
def create_figure():
6769
plt.figure()
6870
x = np.linspace(0, 1, 15)
69-
plt.plot(x, x**2, "b-")
70-
plt.plot(x, 1-x**2, "g>")
71+
plt.plot(x, x ** 2, "b-")
72+
plt.plot(x, 1 - x**2, "g>")
7173
plt.plot([0.9], [0.5], "ro", markersize=3)
72-
plt.text(0.9, 0.5, u'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)', ha='right', fontsize=20)
73-
plt.ylabel(u'sans-serif with math $\\frac{\\sqrt{x}}{y^2}$..', family='sans-serif')
74+
plt.text(0.9, 0.5, u'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)',
75+
ha='right', fontsize=20)
76+
plt.ylabel(u'sans-serif with math $\\frac{\\sqrt{x}}{y^2}$..',
77+
family='sans-serif')
7478

7579

7680
# test compiling a figure to pdf with xelatex
@@ -80,7 +84,7 @@ def test_xelatex():
8084
raise SkipTest('xelatex + pgf is required')
8185

8286
rc_xelatex = {'font.family': 'serif',
83-
'pgf.rcfonts': False,}
87+
'pgf.rcfonts': False}
8488
mpl.rcParams.update(rc_xelatex)
8589
create_figure()
8690
compare_figure('pgf_xelatex.pdf')
@@ -128,7 +132,7 @@ def test_rcupdate():
128132
for i, rc_set in enumerate(rc_sets):
129133
mpl.rcParams.update(rc_set)
130134
create_figure()
131-
compare_figure('pgf_rcupdate%d.pdf' % (i+1))
135+
compare_figure('pgf_rcupdate%d.pdf' % (i + 1))
132136

133137

134138
# test backend-side clipping, since large numbers are not supported by TeX
@@ -147,4 +151,4 @@ def test_pathclip():
147151

148152
if __name__ == '__main__':
149153
import nose
150-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
154+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
from __future__ import print_function
2-
import matplotlib.pyplot as plt
3-
import numpy as np
4-
import sys
52
from io import BytesIO
63
import xml.parsers.expat
7-
from matplotlib.testing.decorators import knownfailureif, cleanup
4+
5+
import numpy as np
6+
7+
import matplotlib.pyplot as plt
8+
from matplotlib.testing.decorators import cleanup
89
from matplotlib.testing.decorators import image_comparison
910

11+
1012
@cleanup
1113
def test_visibility():
12-
# This is SF 2856495. See
13-
# https://sourceforge.net/tracker/?func=detail&aid=2856495&group_id=80706&atid=560720
14-
fig=plt.figure()
15-
ax=fig.add_subplot(1,1,1)
14+
fig = plt.figure()
15+
ax = fig.add_subplot(111)
1616

17-
x = np.linspace(0,4*np.pi,50)
17+
x = np.linspace(0, 4 * np.pi, 50)
1818
y = np.sin(x)
1919
yerr = np.ones_like(y)
2020

21-
a,b,c=ax.errorbar(x,y,yerr=yerr,fmt='ko')
21+
a, b, c = ax.errorbar(x, y, yerr=yerr, fmt='ko')
2222
for artist in b:
2323
artist.set_visible(False)
2424

2525
fd = BytesIO()
26-
fig.savefig(fd,format='svg')
26+
fig.savefig(fd, format='svg')
2727

2828
fd.seek(0)
2929
buf = fd.read()
3030
fd.close()
3131

3232
parser = xml.parsers.expat.ParserCreate()
33-
parser.Parse(buf) # this will raise ExpatError if the svg is invalid
33+
parser.Parse(buf) # this will raise ExpatError if the svg is invalid
34+
3435

3536
@image_comparison(baseline_images=['noscale'], remove_text=True)
3637
def test_noscale():
3738
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
38-
Z = np.sin(Y**2)
39+
Z = np.sin(Y ** 2)
3940

4041
fig = plt.figure()
4142
ax = fig.add_subplot(1, 1, 1)
4243
ax.imshow(Z, cmap='gray')
4344
plt.rcParams['svg.image_noscale'] = True
45+
46+
47+
if __name__ == '__main__':
48+
import nose
49+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_basic.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
from __future__ import print_function
2+
23
from nose.tools import assert_equal
4+
35
from matplotlib.testing.decorators import knownfailureif
4-
import sys
6+
from pylab import *
7+
58

69
def test_simple():
7-
assert_equal(1+1,2)
10+
assert_equal(1 + 1, 2)
11+
812

913
@knownfailureif(True)
1014
def test_simple_knownfail():
11-
assert_equal(1+1,3)
15+
# Test the known fail mechanism.
16+
assert_equal(1 + 1, 3)
17+
1218

13-
from pylab import *
1419
def test_override_builtins():
1520
ok_to_override = set([
1621
'__name__',
@@ -20,7 +25,6 @@ def test_override_builtins():
2025
'all',
2126
'sum'
2227
])
23-
2428
if sys.version_info[0] >= 3:
2529
builtins = sys.modules['builtins']
2630
else:
@@ -30,8 +34,13 @@ def test_override_builtins():
3034
for key in globals().keys():
3135
if key in dir(builtins):
3236
if (globals()[key] != getattr(builtins, key) and
33-
key not in ok_to_override):
37+
key not in ok_to_override):
3438
print("'%s' was overridden in globals()." % key)
3539
overridden = True
3640

3741
assert not overridden
42+
43+
44+
if __name__ == '__main__':
45+
import nose
46+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
from __future__ import print_function
2+
3+
import numpy as np
4+
15
from matplotlib import rcParams, rcParamsDefault
26
from matplotlib.testing.decorators import image_comparison
37
import matplotlib.pyplot as plt
48
import matplotlib.path as mpath
59
import matplotlib.patches as mpatches
610
from matplotlib.ticker import FuncFormatter
7-
import numpy as np
11+
812

913
@image_comparison(baseline_images=['bbox_inches_tight'], remove_text=True,
1014
savefig_kwarg=dict(bbox_inches='tight'), tol=15)
1115
def test_bbox_inches_tight():
12-
"Test that a figure saved using bbox_inches'tight' is clipped right"
16+
#: Test that a figure saved using bbox_inches='tight' is clipped right
1317
rcParams.update(rcParamsDefault)
1418

15-
data = [[ 66386, 174296, 75131, 577908, 32015],
16-
[ 58230, 381139, 78045, 99308, 160454],
17-
[ 89135, 80552, 152558, 497981, 603535],
18-
[ 78415, 81858, 150656, 193263, 69638],
19-
[ 139361, 331509, 343164, 781380, 52269]]
19+
data = [[66386, 174296, 75131, 577908, 32015],
20+
[58230, 381139, 78045, 99308, 160454],
21+
[89135, 80552, 152558, 497981, 603535],
22+
[78415, 81858, 150656, 193263, 69638],
23+
[139361, 331509, 343164, 781380, 52269]]
2024

2125
colLabels = rowLabels = [''] * 5
2226

@@ -26,13 +30,13 @@ def test_bbox_inches_tight():
2630
width = 0.4 # the width of the bars
2731
yoff = np.array([0.0] * len(colLabels))
2832
# the bottom values for stacked bar chart
29-
fig, ax = plt.subplots(1,1)
33+
fig, ax = plt.subplots(1, 1)
3034
for row in xrange(rows):
3135
plt.bar(ind, data[row], width, bottom=yoff)
3236
yoff = yoff + data[row]
3337
cellText.append([''])
3438
plt.xticks([])
35-
plt.legend([''] * 5, loc = (1.2, 0.2))
39+
plt.legend([''] * 5, loc=(1.2, 0.2))
3640
# Add a table at the bottom of the axes
3741
cellText.reverse()
3842
the_table = plt.table(cellText=cellText,
@@ -71,8 +75,8 @@ def test_bbox_inches_tight_clipping():
7175

7276
# make a massive rectangle and clip it with a path
7377
patch = mpatches.Rectangle([-50, -50], 100, 100,
74-
transform=ax.transData,
75-
facecolor='blue', alpha=0.5)
78+
transform=ax.transData,
79+
facecolor='blue', alpha=0.5)
7680

7781
path = mpath.Path.unit_regular_star(5).deepcopy()
7882
path.vertices *= 0.25

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,14 @@ class StandardReportWithExclusions(pep8.StandardReport):
6161
'*/matplotlib/tri/triinterpolate.py',
6262
'*/matplotlib/tri/tripcolor.py',
6363
'*/matplotlib/tri/triplot.py',
64-
'*/matplotlib/tests/__init__.py',
6564
'*/matplotlib/tests/test_axes.py',
66-
'*/matplotlib/tests/test_backend_pdf.py',
67-
'*/matplotlib/tests/test_backend_pgf.py',
68-
'*/matplotlib/tests/test_backend_svg.py',
69-
'*/matplotlib/tests/test_basic.py',
70-
'*/matplotlib/tests/test_bbox_tight.py',
7165
'*/matplotlib/tests/test_dates.py',
7266
'*/matplotlib/tests/test_delaunay.py',
7367
'*/matplotlib/tests/test_dviread.py',
7468
'*/matplotlib/tests/test_image.py',
7569
'*/matplotlib/tests/test_legend.py',
7670
'*/matplotlib/tests/test_lines.py',
7771
'*/matplotlib/tests/test_mathtext.py',
78-
'*/matplotlib/tests/test_patches.py',
79-
'*/matplotlib/tests/test_pickle.py',
80-
'*/matplotlib/tests/test_png.py',
8172
'*/matplotlib/tests/test_rcparams.py',
8273
'*/matplotlib/tests/test_simplification.py',
8374
'*/matplotlib/tests/test_spines.py',

0 commit comments

Comments
 (0)
0