8000 Tests starting with a c are all now PEP8 compliant. · matplotlib/matplotlib@a9fc091 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9fc091

Browse files
committed
Tests starting with a c are all now PEP8 compliant.
1 parent d5071f4 commit a9fc091

File tree

6 files changed

+93
-60
lines changed

6 files changed

+93
-60
lines changed

lib/matplotlib/tests/test_cbook.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
from __future__ import print_function
2+
3+
from datetime import datetime
4+
5+
from nose.tools import assert_equal, raises
26
import numpy as np
37
from numpy.testing.utils import assert_array_equal
8+
49
import matplotlib.cbook as cbook
510
import matplotlib.colors as mcolors
6-
from nose.tools import assert_equal, raises
7-
from datetime import datetime
11+
from matplotlib.cbook import delete_masked_points as dmp
12+
813

914
def test_is_string_like():
10-
y = np.arange( 10 )
11-
assert_equal( cbook.is_string_like( y ), False )
15+
y = np.arange(10)
16+
assert_equal(cbook.is_string_like(y), False)
1217
y.shape = 10, 1
13-
assert_equal( cbook.is_string_like( y ), False )
18+
assert_equal(cbook.is_string_like(y), False)
1419
y.shape = 1, 10
15-
assert_equal( cbook.is_string_like( y ), False )
20+
assert_equal(cbook.is_string_like(y), False)
21+
22+
assert cbook.is_string_like("hello world")
23+
assert_equal(cbook.is_string_like(10), False)
1624

17-
assert cbook.is_string_like( "hello world" )
18-
assert_equal( cbook.is_string_like(10), False )
1925

2026
def test_restrict_dict():
2127
d = {'foo': 'bar', 1: 2}
@@ -27,18 +33,17 @@ def test_restrict_dict():
2733
assert_equal(d3, {'foo': 'bar'})
2834
d4 = cbook.restrict_dict(d, {})
2935
assert_equal(d4, {})
30-
d5 = cbook.restrict_dict(d, set(['foo',2]))
36+
d5 = cbook.restrict_dict(d, set(['foo', 2]))
3137
assert_equal(d5, {'foo': 'bar'})
3238
# check that d was not modified
3339
assert_equal(d, {'foo': 'bar', 1: 2})
3440

35-
from matplotlib.cbook import delete_masked_points as dmp
3641

3742
class Test_delete_masked_points:
3843
def setUp(self):
3944
self.mask1 = [False, False, True, True, False, False]
40-
self.arr0 = np.arange(1.0,7.0)
41-
self.arr1 = [1,2,3,np.nan,np.nan,6]
45+
self.arr0 = np.arange(1.0, 7.0)
46+
self.arr1 = [1, 2, 3, np.nan, np.nan, 6]
4247
self.arr2 = np.array(self.arr1)
4348
self.arr3 = np.ma.array(self.arr2, mask=self.mask1)
4449
self.arr_s = ['a', 'b', 'c', 'd', 'e', 'f']

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ class StandardReportWithExclusions(pep8.StandardReport):
7272
'*/matplotlib/tests/test_backend_svg.py',
7373
'*/matplotlib/tests/test_basic.py',
7474
'*/matplotlib/tests/test_bbox_tight.py',
75-
'*/matplotlib/tests/test_cbook.py',
76-
'*/matplotlib/tests/test_colorbar.py',
77-
'*/matplotlib/tests/test_colors.py',
78-
'*/matplotlib/tests/test_compare_images.py',
79-
'*/matplotlib/tests/test_contour.py',
8075
'*/matplotlib/tests/test_dates.py',
8176
'*/matplotlib/tests/test_delaunay.py',
8277
'*/matplotlib/tests/test_dviread.py',

lib/matplotlib/tests/test_colorbar.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def _get_cmap_norms():
2222
clevs = [-5., -2.5, -.5, .5, 1.5, 3.5]
2323
# Define norms for the color maps.
2424
norms = dict()
25-
norms['neither'] = BoundaryNorm(clevs, len(clevs)-1)
26-
norms['min'] = BoundaryNorm([-10]+clevs[1:], len(clevs)-1)
27-
norms['max'] = BoundaryNorm(clevs[:-1]+[10], len(clevs)-1)
28-
norms['both'] = BoundaryNorm([-10]+clevs[1:-1]+[10], len(clevs)-1)
25+
norms['neither'] = BoundaryNorm(clevs, len(clevs) - 1)
26+
norms['min'] = BoundaryNorm([-10] + clevs[1:], len(clevs) - 1)
27+
norms['max'] = BoundaryNorm(clevs[:-1] + [10], len(clevs) - 1)
28+
norms['both'] = BoundaryNorm([-10] + clevs[1:-1] + [10], len(clevs) - 1)
2929
return cmap, norms
3030

3131

@@ -46,7 +46,7 @@ def _colorbar_extension_shape(spacing):
4646
norm = norms[extension_type]
4747
boundaries = values = norm.boundaries
4848
# Create a subplot.
49-
cax = fig.add_subplot(4, 1, i+1)
49+
cax = fig.add_subplot(4, 1, i + 1)
5050
# Turn off text and ticks.
5151
for item in cax.get_xticklabels() + cax.get_yticklabels() +\
5252
cax.get_xticklines() + cax.get_yticklines():
@@ -78,7 +78,7 @@ def _colorbar_extension_length(spacing):
7878
boundaries = values = norm.boundaries
7979
for j, extendfrac in enumerate((None, 'auto', 0.1)):
8080
# Create a subplot.
81-
cax = fig.add_subplot(12, 1, i*3+j+1)
81+
cax = fig.add_subplot(12, 1, i*3 + j + 1)
8282
# Turn off text and ticks.
8383
for item in cax.get_xticklabels() + cax.get_yticklabels() +\
8484
cax.get_xticklines() + cax.get_yticklines():
@@ -128,19 +128,19 @@ def test_colorbar_positioning():
128128
data = np.arange(1200).reshape(30, 40)
129129
levels = [0, 200, 400, 600, 800, 1000, 1200]
130130

131+
# -------------------
131132
plt.figure()
132133
plt.contourf(data, levels=levels)
133134
plt.colorbar(orientation='horizontal', use_gridspec=False)
134135

135-
136136
locations = ['left', 'right', 'top', 'bottom']
137137
plt.figure()
138138
for i, location in enumerate(locations):
139-
plt.subplot(2, 2, i+1)
139+
plt.subplot(2, 2, i + 1)
140140
plt.contourf(data, levels=levels)
141141
plt.colorbar(location=location, use_gridspec=False)
142142

143-
143+
# -------------------
144144
plt.figure()
145145
# make some other data (random integers)
146146
data_2nd = np.array([[2, 3, 2, 3], [1.5, 2, 2, 3], [2, 3, 3, 4]])
@@ -149,13 +149,16 @@ def test_colorbar_positioning():
149149

150150
color_mappable = plt.contourf(data, levels=levels, extend='both')
151151
# test extend frac here
152-
hatch_mappable = plt.contourf(data_2nd, levels=[1, 2, 3], colors='none', hatches=['/', 'o', '+'], extend='max')
152+
hatch_mappable = plt.contourf(data_2nd, levels=[1, 2, 3], colors='none',
153+
hatches=['/', 'o', '+'], extend='max')
153154
plt.contour(hatch_mappable, colors='black')
154155

155-
plt.colorbar(color_mappable, location='left', label='variable 1', use_gridspec=False)
156-
plt.colorbar(hatch_mappable, location='right', label='variable 2', use_gridspec=False)
157-
156+
plt.colorbar(color_mappable, location='left', label='variable 1',
157+
use_gridspec=False)
158+
plt.colorbar(hatch_mappable, location='right', label='variable 2',
159+
use_gridspec=False)
158160

161+
# -------------------
159162
plt.figure()
160163
ax1 = plt.subplot(211, anchor='NE', aspect='equal')
161164
plt.contourf(data, levels=levels)
@@ -164,9 +167,12 @@ def test_colorbar_positioning():
164167
ax3 = plt.subplot(224)
165168
plt.contourf(data, levels=levels)
166169

167-
plt.colorbar(ax=[ax2, ax3, ax1], location='right', pad=0.0, shrink=0.5, panchor=False, use_gridspec=False)
168-
plt.colorbar(ax=[ax2, ax3, ax1], location='left', shrink=0.5, panchor=False, use_gridspec=False)
169-
plt.colorbar(ax=[ax1], location='bottom', panchor=False, anchor=(0.8, 0.5), shrink=0.6, use_gridspec=False)
170+
plt.colorbar(ax=[ax2, ax3, ax1], location='right', pad=0.0, shrink=0.5,
171+
panchor=False, use_gridspec=False)
172+
plt.colorbar(ax=[ax2, ax3, ax1], location='left', shrink=0.5,
173+
panchor=False, use_gridspec=False)
174+
plt.colorbar(ax=[ax1], location='bottom', panchor=False,
175+
anchor=(0.8, 0.5), shrink=0.6, use_gridspec=False)
170176

171177

172178
@image_comparison(baseline_images=['cbar_with_subplots_adjust'],
@@ -188,6 +194,6 @@ def test_gridspec_make_colorbar():
188194
plt.subplots_adjust(top=0.95, right=0.95, bottom=0.2, hspace=0.25)
189195

190196

191-
if __name__=='__main__':
197+
if __name__ == '__main__':
192198
import nose
193-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
199+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_colors.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
"""
2-
Tests for the colors module.
3-
"""
4-
51
from __future__ import print_function
2+
63
import numpy as np
74
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
5+
86
import matplotlib.colors as mcolors
97
import matplotlib.cm as cm
108

9+
1110
def test_colormap_endian():
1211
"""
1312
Github issue #1005: a bug in putmask caused erroneous
@@ -23,6 +22,7 @@ def test_colormap_endian():
2322
#print(anative.dtype.isnative, aforeign.dtype.isnative)
2423
assert_array_equal(cmap(anative), cmap(aforeign))
2524

25+
2626
def test_BoundaryNorm():
2727
"""
2828
Github issue #1258: interpolation was failing with numpy
@@ -36,7 +36,8 @@ def test_BoundaryNorm():
3636
ncolors = len(boundaries)
3737
bn = mcolors.BoundaryNorm(boundaries, ncolors)
3838
assert_array_equal(bn(vals), expected)
39-
39+
40+
4041
def test_LogNorm():
4142
"""
4243
LogNorm igornoed clip, now it has the same
@@ -46,6 +47,7 @@ def test_LogNorm():
4647
ln = mcolors.LogNorm(clip=True, vmax=5)
4748
assert_array_equal(ln([1, 6]), [0, 1.0])
4849

50+
4951
def test_Normalize():
5052
norm = mcolors.Normalize()
5153
vals = np.arange(-10, 10, 1, dtype=np.float)
@@ -61,7 +63,7 @@ def test_SymLogNorm():
6163
norm = mcolors.SymLogNorm(3, vmax=5, linscale=1.2)
6264
vals = np.array([-30, -1, 2, 6], dtype=np.float)
6365
normed_vals = norm(vals)
64-
expected = [ 0., 0.53980074, 0.826991, 1.02758204]
66+
expected = [0., 0.53980074, 0.826991, 1.02758204]
6567
assert_array_almost_equal(normed_vals, expected)
6668
_inverse_tester(norm, vals)
6769
_scalar_tester(norm, vals)
@@ -74,6 +76,7 @@ def _inverse_tester(norm_instance, vals):
7476
"""
7577
assert_array_almost_equal(norm_instance.inverse(norm_instance(vals)), vals)
7678

79+
7780
def _scalar_tester(norm_instance, vals):
7881
"""
7982
Checks if scalars and arrays are handled the same way.
@@ -82,10 +85,16 @@ def _scalar_tester(norm_instance, vals):
8285
scalar_result = [norm_instance(float(v)) for v in vals]
8386
assert_array_almost_equal(scalar_result, norm_instance(vals))
8487

88+
8589
def _mask_tester(norm_instance, vals):
8690
"""
8791
Checks mask handling
8892
"""
8993
masked_array = np.ma.array(vals)
9094
masked_array[0] = np.ma.masked
9195
assert_array_equal(masked_array.mask, norm_instance(masked_array).mask)
96+
97+
98+
if __name__ == '__main__':
99+
import nose
100+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_compare_images.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from __future__ import print_function
2-
from matplotlib.testing.compare import compare_images
3-
from matplotlib.testing.decorators import _image_directories
4-
from nose.tools import assert_equal, assert_not_equal, assert_almost_equal
52
import os
63
import shutil
74

5+
from nose.tools import assert_equal, assert_not_equal, assert_almost_equal
6+
7+
from matplotlib.testing.compare import compare_images
8+
from matplotlib.testing.decorators import _image_directories
9+
10+
811
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
912

13+
1014
# Tests of the image comparison algorithm.
1115
def image_comparison_expect_rms(im1, im2, tol, expect_rms):
1216
"""Compare two images, expecting a particular RMS error.
@@ -34,8 +38,10 @@ def image_comparison_expect_rms(im1, im2, tol, expect_rms):
3438
assert_not_equal(None, results)
3539
assert_almost_equal(expect_rms, results['rms'], places=4)
3640

41+
3742
def test_image_compare_basic():
38-
"""Test comparison of an image and the same image with minor differences."""
43+
#: Test comparison of an image and the same image with minor differences.
44+
3945
# This expects the images to compare equal under normal tolerance, and have
4046
# a small RMS.
4147
im1 = 'basn3p02.png'
@@ -45,23 +51,27 @@ def test_image_compare_basic():
4551
# Now test with no tolerance.
4652
image_comparison_expect_rms(im1, im2, tol=0, expect_rms=6.50646)
4753

54+
4855
def test_image_compare_1px_offset():
49-
"""Test comparison with an image that is shifted by 1px in the X axis."""
56+
#: Test comparison with an image that is shifted by 1px in the X axis.
5057
im1 = 'basn3p02.png'
5158
im2 = 'basn3p02-1px-offset.png'
5259
image_comparison_expect_rms(im1, im2, tol=0, expect_rms=90.15611)
5360

61+
5462
def test_image_compare_half_1px_offset():
55-
"""Test comparison with an image with half the pixels shifted by 1px in the
56-
X axis."""
63+
#: Test comparison with an image with half the pixels shifted by 1px in
64+
#: the X axis.
5765
im1 = 'basn3p02.png'
5866
im2 = 'basn3p02-half-1px-offset.png'
5967
image_comparison_expect_rms(im1, im2, tol=0, expect_rms=63.75)
6068

69+
6170
def test_image_compare_scrambled():
62-
"""Test comparison of an image and the same image scrambled."""
63-
# This expects the images to compare completely different, with a very large
64-
# RMS.
71+
#: Test comparison of an image and the same image scrambled.
72+
73+
# This expects the images to compare completely different, with a very
74+
# large RMS.
6575
# Note: The image has been scrambled in a specific way, by having each
6676
# color component of each pixel randomly placed somewhere in the image. It
6777
# contains exactly the same number of pixels of each color value of R, G
@@ -72,8 +82,9 @@ def test_image_compare_scrambled():
7282
# error.
7383
image_comparison_expect_rms(im1, im2, tol=0, expect_rms=172.63582)
7484

85+
7586
def test_image_compare_shade_difference():
76-
"""Test comparison of an image and a slightly brighter image."""
87+
#: Test comparison of an image and a slightly brighter image.
7788
# The two images are solid color, with the second image being exactly 1
7889
# color value brighter.
7990
# This expects the images to compare equal under normal tolerance, and have
@@ -84,3 +95,8 @@ def test_image_compare_shade_difference():
8495

8596
# Now test the reverse comparison.
8697
image_comparison_expect_rms(im2, im1, tol=0, expect_rms=1.0)
98+
99+
100+
if __name__ == '__main__':
101+
import nose
102+
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_contour.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_contour_manual_labels():
146146
z = np.max(np.dstack([abs(x), abs(y)]), 2)
147147

148148
plt.figure(figsize=(6, 2))
149-
cs = plt.contour(x,y,z)
149+
cs = plt.contour(x, y, z)
150150
pts = np.array([(1.5, 3.0), (1.5, 4.4), (1.5, 6.0)])
151151
plt.clabel(cs, manual=pts)
152152

@@ -157,23 +157,25 @@ def test_given_colors_levels_and_extends():
157157
_, axes = plt.subplots(2, 4)
158158

159159
data = np.arange(12).reshape(3, 4)
160-
160+
161161
colors = ['red', 'yellow', 'pink', 'blue', 'black']
162162
levels = [2, 4, 8, 10]
163-
163+
164164
for i, ax in enumerate(axes.flatten()):
165165
plt.sca(ax)
166-
166+
167167
filled = i % 2 == 0.
168168
extend = ['neither', 'min', 'max', 'both'][i // 2]
169-
169+
170170
if filled:
171171
last_color = -1 if extend in ['min', 'max'] else None
172-
plt.contourf(data, colors=colors[:last_color], levels=levels, extend=extend)
172+
plt.contourf(data, colors=colors[:last_color], levels=levels,
173+
extend=extend)
173174
else:
174175
last_level = -1 if extend == 'both' else None
175-
plt.contour(data, colors=colors, levels=levels[:last_level], extend=extend)
176-
176+
plt.contour(data, colors=colors, levels=levels[:last_level],
177+
extend=extend)
178+
177179
plt.colorbar()
178180

179181

0 commit comments

Comments
 (0)
0