Skip to content

Commit 1b666c5

Browse files
authored
Merge pull request #7336 from QuLogic/fix-test-warnings
Fix some test warnings
2 parents 236700c + 538bff5 commit 1b666c5

11 files changed

+36
-22
lines changed

lib/matplotlib/afm.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
... 'fonts', 'afm', 'ptmr8a.afm')
2020
>>>
2121
>>> from matplotlib.afm import AFM
22-
>>> afm = AFM(open(afm_fname))
22+
>>> with open(afm_fname) as fh:
23+
... afm = AFM(fh)
2324
>>> afm.string_width_height('What the heck?')
2425
(6220.0, 694)
2526
>>> afm.get_fontname()

lib/matplotlib/animation.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,9 @@ def grab_frame(self, **savefig_kwargs):
413413
try:
414414
# Tell the figure to save its data to the sink, using the
415415
# frame format and dpi.
416-
myframesink = self._frame_sink()
417-
self.fig.savefig(myframesink, format=self.frame_format,
418-
dpi=self.dpi, **savefig_kwargs)
419-
myframesink.close()
416+
with self._frame_sink() as myframesink:
417+
self.fig.savefig(myframesink, format=self.frame_format,
418+
dpi=self.dpi, **savefig_kwargs)
420419

421420
except RuntimeError:
422421
out, err = self._proc.communicate()

lib/matplotlib/stackplot.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def stackplot(axes, x, *args, **kwargs):
9292
center = np.zeros(n)
9393
total = np.sum(y, 0)
9494
# multiply by 1/total (or zero) to avoid infinities in the division:
95-
inv_total = np.where(total > 0, 1./total, 0)
95+
inv_total = np.zeros_like(total)
96+
mask = total > 0
97+
inv_total[mask] = 1.0 / total[mask]
9698
increase = np.hstack((y[:, 0:1], np.diff(y)))
9799
below_size = total - stack
98100
below_size += 0.5 * y

lib/matplotlib/tests/test_basic.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33

44
import six
55

6+
import warnings
7+
68
from nose.tools import assert_equal
79

10+
from matplotlib.cbook import MatplotlibDeprecationWarning
811
from matplotlib.testing.decorators import knownfailureif
9-
from pylab import *
12+
with warnings.catch_warnings():
13+
warnings.filterwarnings('ignore',
14+
'The finance module has been deprecated in mpl 2',
15+
MatplotlibDeprecationWarning)
16+
from pylab import *
1017

1118

1219
def test_simple():

lib/matplotlib/tests/test_collections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def get_transform(self):
578578
@cleanup
579579
def test_picking():
580580
fig, ax = plt.subplots()
581-
col = ax.scatter([0], [0], [1000])
581+
col = ax.scatter([0], [0], [1000], picker=True)
582582
fig.savefig(io.BytesIO(), dpi=fig.dpi)
583583

584584
class MouseEvent(object):

lib/matplotlib/tests/test_contour.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,18 @@ def test_contour_shape_mismatch_4():
108108
try:
109109
ax.contour(b, g, z)
110110
except TypeError as exc:
111-
print(exc.args[0])
112111
assert re.match(
113112
r'Shape of x does not match that of z: ' +
114113
r'found \(9L?, 9L?\) instead of \(9L?, 10L?\)\.',
115-
exc.args[0]) is not None
114+
exc.args[0]) is not None, exc.args[0]
116115

117116
try:
118117
ax.contour(g, b, z)
119118
except TypeError as exc:
120119
assert re.match(
121120
r'Shape of y does not match that of z: ' +
122121
r'found \(9L?, 9L?\) instead of \(9L?, 10L?\)\.',
123-
exc.args[0]) is not None
122+
exc.args[0]) is not None, exc.args[0]
124123

125124

126125
@cleanup

lib/matplotlib/tests/test_cycles.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import warnings
22

33
from matplotlib.testing.decorators import image_comparison, cleanup
4+
from matplotlib.cbook import MatplotlibDeprecationWarning
45
import matplotlib.pyplot as plt
56
import numpy as np
67
from nose.tools import assert_raises
@@ -184,6 +185,7 @@ def test_cycle_reset():
184185
fig, ax = plt.subplots()
185186
# Need to double-check the old set/get_color_cycle(), too
186187
with warnings.catch_warnings():
188+
warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
187189
prop = next(ax._get_lines.prop_cycler)
188190
ax.set_color_cycle(['c', 'm', 'y', 'k'])
189191
assert prop != next(ax._get_lines.prop_cycler)

lib/matplotlib/tests/test_simplification.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
99
import matplotlib.pyplot as plt
1010

11-
from pylab import *
12-
import numpy as np
1311
from matplotlib import patches, path, transforms
1412

1513
from nose.tools import raises
@@ -24,7 +22,7 @@
2422
@image_comparison(baseline_images=['clipping'], remove_text=True)
2523
def test_clipping():
2624
t = np.arange(0.0, 2.0, 0.01)
27-
s = np.sin(2*pi*t)
25+
s = np.sin(2*np.pi*t)
2826

2927
fig = plt.figure()
3028
ax = fig.add_subplot(111)
@@ -101,16 +99,16 @@ def test_simplify_curve():
10199
def test_hatch():
102100
fig = plt.figure()
103101
ax = fig.add_subplot(111)
104-
ax.add_patch(Rectangle((0, 0), 1, 1, fill=False, hatch="/"))
102+
ax.add_patch(plt.Rectangle((0, 0), 1, 1, fill=False, hatch="/"))
105103
ax.set_xlim((0.45, 0.55))
106104
ax.set_ylim((0.45, 0.55))
107105

108106
@image_comparison(baseline_images=['fft_peaks'], remove_text=True)
109107
def test_fft_peaks():
110108
fig = plt.figure()
111-
t = arange(65536)
109+
t = np.arange(65536)
112110
ax = fig.add_subplot(111)
113-
p1 = ax.plot(abs(fft(sin(2*pi*.01*t)*blackman(len(t)))))
111+
p1 = ax.plot(abs(np.fft.fft(np.sin(2*np.pi*.01*t)*np.blackman(len(t)))))
114112

115113
path = p1[0].get_path()
116114
transform = p1[0].get_transform()
@@ -163,7 +161,7 @@ def test_start_with_moveto():
163161
@cleanup
164162
@raises(OverflowError)
165163
def test_throw_rendering_complexity_exceeded():
166-
rcParams['path.simplify'] = False
164+
plt.rcParams['path.simplify'] = False
167165
xx = np.arange(200000)
168166
yy = np.random.rand(200000)
169167
yy[1000] = np.nan
@@ -173,7 +171,7 @@ def test_throw_rendering_complexity_exceeded():
173171
try:
174172
fig.savefig(io.BytesIO())
175173
finally:
176-
rcParams['path.simplify'] = True
174+
plt.rcParams['path.simplify'] = True
177175

178176
@image_comparison(baseline_images=['clipper_edge'], remove_text=True)
179177
def test_clipper():

lib/matplotlib/tests/test_streamplot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def test_masks_and_nans():
4141
X, Y, U, V = velocity_field()
4242
mask = np.zeros(U.shape, dtype=bool)
4343
mask[40:60, 40:60] = 1
44-
U = np.ma.array(U, mask=mask)
4544
U[:20, :20] = np.nan
45+
U = np.ma.array(U, mask=mask)
4646
with np.errstate(invalid='ignore'):
4747
plt.streamplot(X, Y, U, V, color=U, cmap=plt.cm.Blues)
4848

lib/matplotlib/tests/test_ticker.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ def test_ScalarFormatter_offset_value():
176176
formatter = ax.get_xaxis().get_major_formatter()
177177

178178
def check_offset_for(left, right, offset):
179-
ax.set_xlim(left, right)
179+
with warnings.catch_warnings(record=True) as w:
180+
warnings.filterwarnings('always', 'Attempting to set identical',
181+
UserWarning)
182+
ax.set_xlim(left, right)
183+
assert_equal(len(w), 1 if left == right else 0)
184+
180185
# Update ticks.
181186
next(ax.get_xaxis().iter_ticks())
182187
assert_equal(formatter.offset, offset)

lib/matplotlib/tests/test_type1font.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def test_Type1Font():
1414
font = t1f.Type1Font(filename)
1515
slanted = font.transform({'slant': 1})
1616
condensed = font.transform({'extend': 0.5})
17-
rawdata = open(filename, 'rb').read()
17+
with open(filename, 'rb') as fd:
18+
rawdata = fd.read()
1819
assert_equal(font.parts[0], rawdata[0x0006:0x10c5])
1920
assert_equal(font.parts[1], rawdata[0x10cb:0x897f])
2021
assert_equal(font.parts[2], rawdata[0x8985:0x8ba6])

0 commit comments

Comments
 (0)