22Provides utilities to test output reproducibility.
33"""
44
5- from __future__ import (absolute_import , division , print_function ,
6- unicode_literals )
7-
8- import six
9-
105import io
116import os
127import re
8+ import subprocess
139import sys
14- from subprocess import check_output
1510
1611import pytest
1712
@@ -34,11 +29,11 @@ def _determinism_save(objects='mhi', format="pdf", usetex=False):
3429 # use different markers...
3530 ax1 = fig .add_subplot (1 , 6 , 1 )
3631 x = range (10 )
37- ax1 .plot (x , [1 ] * 10 , marker = u 'D' )
38- ax1 .plot (x , [2 ] * 10 , marker = u 'x' )
39- ax1 .plot (x , [3 ] * 10 , marker = u '^' )
40- ax1 .plot (x , [4 ] * 10 , marker = u 'H' )
41- ax1 .plot (x , [5 ] * 10 , marker = u 'v' )
32+ ax1 .plot (x , [1 ] * 10 , marker = 'D' )
33+ ax1 .plot (x , [2 ] * 10 , marker = 'x' )
34+ ax1 .plot (x , [3 ] * 10 , marker = '^' )
35+ ax1 .plot (x , [4 ] * 10 , marker = 'H' )
36+ ax1 .plot (x , [5 ] * 10 , marker = 'v' )
4237
4338 if 'h' in objects :
4439 # also use different hatch patterns
@@ -63,13 +58,8 @@ def _determinism_save(objects='mhi', format="pdf", usetex=False):
6358 x = range (5 )
6459 fig .add_subplot (1 , 6 , 6 ).plot (x , x )
6560
66- if six .PY2 and format == 'ps' :
67- stdout = io .StringIO ()
68- else :
69- stdout = getattr (sys .stdout , 'buffer' , sys .stdout )
61+ stdout = getattr (sys .stdout , 'buffer' , sys .stdout )
7062 fig .savefig (stdout , format = format )
71- if six .PY2 and format == 'ps' :
72- sys .stdout .write (stdout .getvalue ())
7363
7464 # Restores SOURCE_DATE_EPOCH
7565 if sde is None :
@@ -94,14 +84,14 @@ def _determinism_check(objects='mhi', format="pdf", usetex=False):
9484 """
9585 plots = []
9686 for i in range (3 ):
97- result = check_output ([sys . executable , '-R' , '-c' ,
98- 'import matplotlib; '
99- 'matplotlib._called_from_pytest = True ; '
100- 'matplotlib.use(%r) ; '
101- 'from matplotlib.testing.determinism '
102- ' import _determinism_save;'
103- '_determinism_save(%r,%r,%r)'
104- % (format , objects , format , usetex )])
87+ result = subprocess . check_output ([
88+ sys . executable , '-R' , '-c' ,
89+ 'import matplotlib ; '
90+ 'matplotlib._called_from_pytest = True ; '
91+ ' matplotlib.use(%r); '
92+ 'from matplotlib.testing.determinism import _determinism_save;'
93+ '_determinism_save(%r, %r, %r)'
94+ % (format , objects , format , usetex )])
10595 plots .append (result )
10696 for p in plots [1 :]:
10797 if usetex :
@@ -128,14 +118,14 @@ def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
128118 a string to look at when searching for the timestamp in the document
129119 (used in case the test fails).
130120 """
131- buff = check_output ([sys . executable , '-R' , '-c' ,
132- 'import matplotlib; '
133- 'matplotlib._called_from_pytest = True ; '
134- 'matplotlib.use(%r) ; '
135- 'from matplotlib.testing.determinism '
136- ' import _determinism_save;'
137- '_determinism_save(%r,%r)'
138- % (format , "" , format )])
121+ buff = subprocess . check_output ([
122+ sys . executable , '-R' , '-c' ,
123+ 'import matplotlib ; '
124+ 'matplotlib._called_from_pytest = True ; '
125+ ' matplotlib.use(%r); '
126+ 'from matplotlib.testing.determinism import _determinism_save;'
127+ '_determinism_save(%r, %r)'
128+ % (format , "" , format )])
139129 find_keyword = re .compile (b".*" + keyword + b".*" )
140130 key = find_keyword .search (buff )
141131 if key :
0 commit comments