Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38e5eab

Browse files
committed
Merge branch 'pep8_on_tests'
Conflicts: lib/matplotlib/tests/test_agg.py lib/matplotlib/tests/test_backend_pdf.py lib/matplotlib/tests/test_backend_pgf.py lib/matplotlib/tests/test_coding_standards.py lib/matplotlib/tests/test_colors.py lib/matplotlib/tests/test_contour.py
2 parents daf7efb + 44b51ac commit 38e5eab

20 files changed

+233
-197
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_agg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import os
55
import tempfile
66

7-
87
from numpy.testing import assert_array_almost_equal
98

10-
119
from matplotlib.image import imread
1210
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
1311
from matplotlib.figure import Figure
@@ -103,7 +101,8 @@ def report_memory(i):
103101
## avgMem = (end - start) / float(N)
104102
## print 'Average memory consumed per loop: %1.4f\n' % (avgMem)
105103

106-
## #TODO: Verify the expected mem usage and approximate tolerance that should be used
104+
## #TODO: Verify the expected mem usage and approximate tolerance that
105+
## # should be used
107106
## #self.checkClose( 0.32, avgMem, absTol = 0.1 )
108107

109108
## # w/o text and w/o write_png: Average memory consumed per loop: 0.02

lib/matplotlib/tests/test_animation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from __future__ import print_function
12
import os
23
import tempfile
4+
35
import numpy as np
6+
47
from matplotlib import pyplot as plt
58
from matplotlib import animation
69
from matplotlib.testing.noseclasses import KnownFailureTest
@@ -13,7 +16,6 @@
1316
imagemagick='gif', imagemagick_file='gif')
1417

1518

16-
1719
# Smoke test for saving animations. In the future, we should probably
1820
# design more sophisticated tests which compare resulting frames a-la
1921
# matplotlib.testing.image_comparison
@@ -46,6 +48,6 @@ def animate(i):
4648
anim.save(F.name, fps=30, writer=writer)
4749

4850

49-
if __name__ == '__main__':
51+
if __name__ == "__main__":
5052
import nose
51-
nose.runmodule()
53+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
from __future__ import print_function
2+
13
import matplotlib.pyplot as plt
24
from matplotlib.testing.decorators import image_comparison
35
import matplotlib
46

7+
58
def draw_arrow(ax, t, r):
6-
ax.annotate('', xy=(0.5, 0.5+r), xytext=(0.5, 0.5), size=30,
9+
ax.annotate('', xy=(0.5, 0.5 + r), xytext=(0.5, 0.5), size=30,
710
arrowprops=dict(arrowstyle=t,
811
fc="b", ec='k'))
912

13+
1014
@image_comparison(baseline_images=['fancyarrow_test_image'])
1115
def test_fancyarrow():
1216
r = [0.4, 0.3, 0.2, 0.1]
1317
t = ["fancy", "simple", matplotlib.patches.ArrowStyle.Fancy()]
1418

1519
fig, axes = plt.subplots(len(t), len(r), squeeze=False,
1620
subplot_kw=dict(aspect=True),
17-
figsize=(8, 4.5))
21+
figsize=(8, 4.5))
1822

1923
for i_r, r1 in enumerate(r):
2024
for i_t, t1 in enumerate(t):
@@ -23,7 +27,6 @@ def test_fancyarrow():
2327
ax.tick_params(labelleft=False, labelbottom=False)
2428

2529

26-
if __name__=='__main__':
30+
if __name__ == '__main__':
2731
import nose
28-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
29-
32+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_artist.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from __future__ import print_function
22

3-
import copy
4-
5-
63
import numpy as np
74

8-
95
import matplotlib.pyplot as plt
106
import matplotlib.patches as mpatches
117
import matplotlib.path as mpath
@@ -93,16 +89,6 @@ def test_collection_transform_of_none():
9389
assert isinstance(c._transOffset, mtrans.IdentityTransform)
9490

9591

96-
def test_point_in_path():
97-
# Test #1787
98-
verts2 = [(0,0), (0,1), (1,1), (1,0), (0,0)]
99-
100-
path = mpath.Path(verts2, closed=True)
101-
points = [(0.5,0.5), (1.5,0.5)]
102-
103-
assert np.all(path.contains_points(points) == [True, False])
104-
105-
10692
@image_comparison(baseline_images=["clip_path_clipping"], remove_text=True)
10793
def test_clipping():
10894
exterior = mpath.Path.unit_rectangle().deepcopy()
@@ -134,6 +120,6 @@ def test_clipping():
134120
ax1.set_ylim([-3, 3])
135121

136122

137-
if __name__=='__main__':
123+
if __name__ == '__main__':
138124
import nose
139-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
125+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# -*- encoding: utf-8 -*-
22

33
import io
4+
import os
45

56
import numpy as np
67

78
from matplotlib import cm, rcParams
89
from matplotlib import pyplot as plt
910
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
10-
import os
11+
1112

1213
if 'TRAVIS' not in os.environ:
1314
@image_comparison(baseline_images=['pdf_use14corefonts'], extensions=['pdf'])
@@ -30,11 +31,17 @@ def test_use14corefonts():
3031
fontsize=24)
3132
plt.axhline(0.5, linewidth=0.5)
3233

34+
3335
@cleanup
3436
def test_type42():
3537
rcParams['pdf.fonttype'] = 42
3638

3739
fig = plt.figure()
3840
ax = fig.add_subplot(111)
39-
ax.plot([1,2,3])
41+
ax.plot([1, 2, 3])
4042
fig.savefig(io.BytesIO())
43+
44+
45+
if __name__ == "__main__":
46+
import nose
47+
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,19 +61,21 @@ 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-")
71+
plt.plot(x, x ** 2, "b-")
7072
plt.fill_between([0., .4], [.4, 0.], hatch='//', facecolor="lightgray", edgecolor="red")
71-
plt.plot(x, 1-x**2, "g>")
73+
plt.plot(x, 1 - x**2, "g>")
7274
plt.plot([0.9], [0.5], "ro", markersize=3)
73-
plt.text(0.9, 0.5, u'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)', ha='right', fontsize=20)
74-
plt.ylabel(u'sans-serif with math $\\frac{\\sqrt{x}}{y^2}$..', family='sans-serif')
75+
plt.text(0.9, 0.5, u'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)',
76+
ha='right', fontsize=20)
77+
plt.ylabel(u'sans-serif with math $\\frac{\\sqrt{x}}{y^2}$..',
78+
family='sans-serif')
7579

7680

7781
# test compiling a figure to pdf with xelatex
@@ -81,7 +85,7 @@ def test_xelatex():
8185
raise SkipTest('xelatex + pgf is required')
8286

8387
rc_xelatex = {'font.family': 'serif',
84-
'pgf.rcfonts': False,}
88+
'pgf.rcfonts': False}
8589
mpl.rcParams.update(rc_xelatex)
8690
create_figure()
8791
compare_figure('pgf_xelatex.pdf')
@@ -129,7 +133,7 @@ def test_rcupdate():
129133
for i, rc_set in enumerate(rc_sets):
130134
mpl.rcParams.update(rc_set)
131135
create_figure()
132-
compare_figure('pgf_rcupdate%d.pdf' % (i+1))
136+
compare_figure('pgf_rcupdate%d.pdf' % (i + 1))
133137

134138

135139
# test backend-side clipping, since large numbers are not supported by TeX
@@ -160,4 +164,4 @@ def test_mixedmode():
160164

161165
if __name__ == '__main__':
162166
import nose
163-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
167+
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__',
@@ -21,7 +26,6 @@ def test_override_builtins():
2126
'all',
2227
'sum'
2328
])
24-
2529
if sys.version_info[0] >= 3:
2630
builtins = sys.modules['builtins']
2731
else:
@@ -31,8 +35,13 @@ def test_override_builtins():
3135
for key in globals().keys():
3236
if key in dir(builtins):
3337
if (globals()[key] != getattr(builtins, key) and
34-
key not in ok_to_override):
38+
key not in ok_to_override):
3539
print("'%s' was overridden in globals()." % key)
3640
overridden = True
3741

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

0 commit comments

Comments
 (0)