Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebff832

Browse files
committed
TST: Fix compatibility with Python 2.
1 parent fb529da commit ebff832

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/matplotlib/testing/determinism.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Provides utilities to test output reproducibility.
33
"""
44

5+
import six
6+
57
import io
68
import os
79
import re
@@ -53,7 +55,13 @@ def _determinism_save(objects='mhi', format="pdf"):
5355
x = range(5)
5456
fig.add_subplot(1, 6, 6).plot(x, x)
5557

56-
fig.savefig(sys.stdout.buffer, format=format)
58+
if six.PY2 and format == 'ps':
59+
stdout = io.StringIO()
60+
else:
61+
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
62+
fig.savefig(stdout, format=format)
63+
if six.PY2 and format == 'ps':
64+
sys.stdout.write(stdout.getvalue())
5765

5866
# Restores SOURCE_DATE_EPOCH
5967
if sde is None:

0 commit comments

Comments
 (0)