Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b666c5

Browse files
authored
Merge pull request#7336 from QuLogic/fix-test-warnings
Fix some test warnings
2 parents236700c +538bff5 commit1b666c5

File tree

11 files changed

+36
-22
lines changed

11 files changed

+36
-22
lines changed

‎lib/matplotlib/afm.py

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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+
withself._frame_sink()asmyframesink:
417+
self.fig.savefig(myframesink,format=self.frame_format,
418+
dpi=self.dpi,**savefig_kwargs)
420419

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

‎lib/matplotlib/stackplot.py

Lines changed: 3 additions & 1 deletion
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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33

44
importsix
55

6+
importwarnings
7+
68
fromnose.toolsimportassert_equal
79

10+
frommatplotlib.cbookimportMatplotlibDeprecationWarning
811
frommatplotlib.testing.decoratorsimportknownfailureif
9-
frompylabimport*
12+
withwarnings.catch_warnings():
13+
warnings.filterwarnings('ignore',
14+
'The finance module has been deprecated in mpl 2',
15+
MatplotlibDeprecationWarning)
16+
frompylabimport*
1017

1118

1219
deftest_simple():

‎lib/matplotlib/tests/test_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def get_transform(self):
578578
@cleanup
579579
deftest_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
classMouseEvent(object):

‎lib/matplotlib/tests/test_contour.py

Lines changed: 2 additions & 3 deletions
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
exceptTypeErrorasexc:
111-
print(exc.args[0])
112111
assertre.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])isnotNone
114+
exc.args[0])isnotNone,exc.args[0]
116115

117116
try:
118117
ax.contour(g,b,z)
119118
exceptTypeErrorasexc:
120119
assertre.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])isnotNone
122+
exc.args[0])isnotNone,exc.args[0]
124123

125124

126125
@cleanup

‎lib/matplotlib/tests/test_cycles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importwarnings
22

33
frommatplotlib.testing.decoratorsimportimage_comparison,cleanup
4+
frommatplotlib.cbookimportMatplotlibDeprecationWarning
45
importmatplotlib.pyplotasplt
56
importnumpyasnp
67
fromnose.toolsimportassert_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
withwarnings.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
assertprop!=next(ax._get_lines.prop_cycler)

‎lib/matplotlib/tests/test_simplification.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
frommatplotlib.testing.decoratorsimportimage_comparison,knownfailureif,cleanup
99
importmatplotlib.pyplotasplt
1010

11-
frompylabimport*
12-
importnumpyasnp
1311
frommatplotlibimportpatches,path,transforms
1412

1513
fromnose.toolsimportraises
@@ -24,7 +22,7 @@
2422
@image_comparison(baseline_images=['clipping'],remove_text=True)
2523
deftest_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
deftest_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
deftest_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
deftest_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
deftest_clipper():

‎lib/matplotlib/tests/test_streamplot.py

Lines changed: 1 addition & 1 deletion
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
withnp.errstate(invalid='ignore'):
4747
plt.streamplot(X,Y,U,V,color=U,cmap=plt.cm.Blues)
4848

‎lib/matplotlib/tests/test_ticker.py

Lines changed: 6 additions & 1 deletion
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
defcheck_offset_for(left,right,offset):
179-
ax.set_xlim(left,right)
179+
withwarnings.catch_warnings(record=True)asw:
180+
warnings.filterwarnings('always','Attempting to set identical',
181+
UserWarning)
182+
ax.set_xlim(left,right)
183+
assert_equal(len(w),1ifleft==rightelse0)
184+
180185
# Update ticks.
181186
next(ax.get_xaxis().iter_ticks())
182187
assert_equal(formatter.offset,offset)

‎lib/matplotlib/tests/test_type1font.py

Lines changed: 2 additions & 1 deletion
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+
withopen(filename,'rb')asfd:
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)

[8]ページ先頭

©2009-2025 Movatter.jp