@@ -119,6 +119,48 @@ def test_bold_font_output_with_none_fonttype():
119
119
ax .set_title ('bold-title' , fontweight = 'bold' )
120
120
121
121
122
+ def _test_determinism (filename ):
123
+ # This function is mostly copy&paste from "def test_visibility"
124
+ # To require no GUI, we use Figure and FigureCanvasSVG
125
+ # instead of plt.figure and fig.savefig
126
+ from matplotlib .figure import Figure
127
+ from matplotlib .backends .backend_svg import FigureCanvasSVG
128
+ from matplotlib import rc
129
+ rc ('svg' , hashsalt = 'asdf' )
130
+
131
+ fig = Figure ()
132
+ ax = fig .add_subplot (111 )
133
+
134
+ x = np .linspace (0 , 4 * np .pi , 50 )
135
+ y = np .sin (x )
136
+ yerr = np .ones_like (y )
137
+
138
+ a , b , c = ax .errorbar (x , y , yerr = yerr , fmt = 'ko' )
139
+ for artist in b :
140
+ artist .set_visible (False )
141
+
142
+ FigureCanvasSVG (fig ).print_svg (filename )
143
+
144
+
145
+ @cleanup
146
+ def test_determinism ():
147
+ import os
148
+ import sys
149
+ from subprocess import check_call
150
+ from nose .tools import assert_equal
151
+ plots = []
152
+ for i in range (3 ):
153
+ check_call ([sys .executable , '-R' , '-c' ,
154
+ 'from matplotlib.tests.test_backend_svg '
155
+ 'import _test_determinism;'
156
+ '_test_determinism("determinism.svg")' ])
157
+ with open ('determinism.svg' , 'rb' ) as fd :
158
+ plots .append (fd .read ())
159
+ os .unlink ('determinism.svg' )
160
+ for p in plots [1 :]:
161
+ assert_equal (p , plots [0 ])
162
+
163
+
122
164
if __name__ == '__main__' :
123
165
import nose
124
166
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments