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

Commit11a5c9f

Browse files
authored
Merge pull request#16036 from anntzer/recwarn
Rely on pytest to record warnings, rather than doing it manually.
2 parentsc041352 +2ad47ca commit11a5c9f

File tree

4 files changed

+20
-36
lines changed

4 files changed

+20
-36
lines changed

‎lib/matplotlib/tests/test_artist.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
importio
22
fromitertoolsimportchain
3-
importwarnings
43

54
importnumpyasnp
65

@@ -220,13 +219,10 @@ def test_default_edges():
220219
ax4.add_patch(pp1)
221220

222221

223-
deftest_properties():
222+
deftest_properties(recwarn):
224223
ln=mlines.Line2D([], [])
225-
withwarnings.catch_warnings(record=True)asw:
226-
# Cause all warnings to always be triggered.
227-
warnings.simplefilter("always")
228-
ln.properties()
229-
assertlen(w)==0
224+
ln.properties()
225+
assertlen(recwarn)==0
230226

231227

232228
deftest_setp():

‎lib/matplotlib/tests/test_axes.py‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5283,17 +5283,13 @@ def test_length_one_hist():
52835283
ax.hist([1])
52845284

52855285

5286-
deftest_pathological_hexbin():
5286+
deftest_pathological_hexbin(recwarn):
52875287
# issue #2863
5288-
out=io.BytesIO()
5289-
5290-
withwarnings.catch_warnings(record=True)asw:
5291-
warnings.simplefilter("always")
5292-
mylist= [10]*100
5293-
fig,ax=plt.subplots(1,1)
5294-
ax.hexbin(mylist,mylist)
5295-
fig.savefig(out)
5296-
assertlen(w)==0
5288+
mylist= [10]*100
5289+
fig,ax=plt.subplots(1,1)
5290+
ax.hexbin(mylist,mylist)
5291+
fig.savefig(io.BytesIO())
5292+
assertlen(recwarn)==0
52975293

52985294

52995295
deftest_color_None():

‎lib/matplotlib/tests/test_image.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
importplatform
77
importsys
88
importurllib.request
9-
importwarnings
109

1110
importnumpyasnp
1211
fromnumpyimportma
@@ -981,11 +980,9 @@ def test_imshow_masked_interpolation():
981980
ax.axis('off')
982981

983982

984-
deftest_imshow_no_warn_invalid():
985-
withwarnings.catch_warnings(record=True)aswarns:
986-
warnings.simplefilter("always")
987-
plt.imshow([[1,2], [3,np.nan]])
988-
assertlen(warns)==0
983+
deftest_imshow_no_warn_invalid(recwarn):
984+
plt.imshow([[1,2], [3,np.nan]])
985+
assertlen(recwarn)==0
989986

990987

991988
@pytest.mark.parametrize(

‎lib/matplotlib/tests/test_quiver.py‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
importwarnings
21
importnumpyasnp
32
importpytest
43
importsys
@@ -72,29 +71,25 @@ def test_quiver_arg_sizes():
7271
plt.quiver(X2,X2,X2,X2,X3)
7372

7473

75-
deftest_no_warnings():
74+
deftest_no_warnings(recwarn):
7675
fig,ax=plt.subplots()
77-
7876
X,Y=np.meshgrid(np.arange(15),np.arange(10))
7977
U=V=np.ones_like(X)
80-
8178
phi= (np.random.rand(15,10)-.5)*150
82-
withwarnings.catch_warnings(record=True)asw:
83-
ax.quiver(X,Y,U,V,angles=phi)
84-
fig.canvas.draw()
85-
assertlen(w)==0
79+
ax.quiver(X,Y,U,V,angles=phi)
80+
fig.canvas.draw()
81+
assertlen(recwarn)==0
8682

8783

88-
deftest_zero_headlength():
84+
deftest_zero_headlength(recwarn):
8985
# Based on report by Doug McNeil:
9086
# http://matplotlib.1069221.n5.nabble.com/quiver-warnings-td28107.html
9187
fig,ax=plt.subplots()
9288
X,Y=np.meshgrid(np.arange(10),np.arange(10))
9389
U,V=np.cos(X),np.sin(Y)
94-
withwarnings.catch_warnings(record=True)asw:
95-
ax.quiver(U,V,headlength=0,headaxislength=0)
96-
fig.canvas.draw()
97-
assertlen(w)==0
90+
ax.quiver(U,V,headlength=0,headaxislength=0)
91+
fig.canvas.draw()
92+
assertlen(recwarn)==0
9893

9994

10095
@image_comparison(['quiver_animated_test_image.png'])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp