Skip to content

Commit 40fc5d6

Browse files
committed
Fixed pickle tests to use the BufferIO object for python3 support.
1 parent cadd152 commit 40fc5d6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/matplotlib/tests/test_pickle.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import cPickle as pickle
1212
#import pickle
1313

14-
from cStringIO import StringIO
14+
from io import BytesIO
1515

1616

1717
def depth_getter(obj,
@@ -87,7 +87,7 @@ def recursive_pickle(top_obj):
8787
for _, obj, location in objs:
8888
# print('trying %s' % location)
8989
try:
90-
pickle.dump(obj, StringIO(), pickle.HIGHEST_PROTOCOL)
90+
pickle.dump(obj, BytesIO(), pickle.HIGHEST_PROTOCOL)
9191
except Exception, err:
9292
print(obj)
9393
print('Failed to pickle %s. \n Type: %s. Traceback follows:' % (location, type(obj)))
@@ -99,21 +99,21 @@ def test_simple():
9999
fig = plt.figure()
100100
# un-comment to debug
101101
# recursive_pickle(fig)
102-
pickle.dump(fig, StringIO(), pickle.HIGHEST_PROTOCOL)
102+
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)
103103

104104
ax = plt.subplot(121)
105-
pickle.dump(ax, StringIO(), pickle.HIGHEST_PROTOCOL)
105+
pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
106106

107107
ax = plt.axes(projection='polar')
108108
plt.plot(range(10), label='foobar')
109109
plt.legend()
110110

111111
# recursive_pickle(fig)
112-
pickle.dump(ax, StringIO(), pickle.HIGHEST_PROTOCOL)
112+
pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
113113

114114
# ax = plt.subplot(121, projection='hammer')
115115
# recursive_pickle(ax, 'figure')
116-
# pickle.dump(ax, StringIO(), pickle.HIGHEST_PROTOCOL)
116+
# pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
117117

118118

119119
@image_comparison(baseline_images=['multi_pickle'],
@@ -163,7 +163,7 @@ def test_complete():
163163
# Uncomment to debug any unpicklable objects. This is slow (~200 seconds).
164164
# recursive_pickle(fig)
165165

166-
result_fh = StringIO()
166+
result_fh = BytesIO()
167167
pickle.dump(fig, result_fh, pickle.HIGHEST_PROTOCOL)
168168

169169
plt.close('all')
@@ -196,4 +196,4 @@ def test_no_pyplot():
196196
# Uncomment to debug any unpicklable objects. This is slow so is not
197197
# uncommented by default.
198198
# recursive_pickle(fig)
199-
pickle.dump(fig, StringIO(), pickle.HIGHEST_PROTOCOL)
199+
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)

0 commit comments

Comments
 (0)