@@ -114,34 +114,23 @@ def _test_source_date_epoch(format, string, keyword=b"CreationDate"):
114
114
a string to look at when searching for the timestamp in the document
115
115
(used in case the test fails).
116
116
"""
117
- try :
118
- # save current value of SOURCE_DATE_EPOCH
119
- sde = os .environ .pop ('SOURCE_DATE_EPOCH' , None )
120
- fig = plt .figure ()
121
- ax = fig .add_subplot (1 , 1 , 1 )
122
- x = [1 , 2 , 3 , 4 , 5 ]
123
- ax .plot (x , x )
124
- os .environ ['SOURCE_DATE_EPOCH' ] = "946684800"
125
- find_keyword = re .compile (b".*" + keyword + b".*" )
126
- with io .BytesIO () as output :
127
- fig .savefig (output , format = format )
128
- output .seek (0 )
129
- buff = output .read ()
130
- key = find_keyword .search (buff )
131
- if key :
132
- print (key .group ())
133
- else :
134
- print ("Timestamp keyword (%s) not found!" % keyword )
135
- assert string in buff
136
- os .environ .pop ('SOURCE_DATE_EPOCH' , None )
137
- with io .BytesIO () as output :
138
- fig .savefig (output , format = format )
139
- output .seek (0 )
140
- buff = output .read ()
141
- assert string not in buff
142
- finally :
143
- # Restores SOURCE_DATE_EPOCH
144
- if sde is None :
145
- os .environ .pop ('SOURCE_DATE_EPOCH' , None )
117
+ import sys
118
+ from subprocess import check_call
119
+ filename = 'test_SDE_on.%s' % format
120
+ check_call ([sys .executable , '-R' , '-c' ,
121
+ 'import matplotlib; '
122
+ 'matplotlib.use(%r); '
123
+ 'from matplotlib.testing.determinism '
124
+ 'import _test_determinism_save;'
125
+ '_test_determinism_save(%r,%r,%r)'
126
+ % (format , filename , "" , format )])
127
+ find_keyword = re .compile (b".*" + keyword + b".*" )
128
+ with open (filename , 'rb' ) as fd :
129
+ buff = fd .read ()
130
+ key = find_keyword .search (buff )
131
+ if key :
132
+ print (key .group ())
146
133
else :
147
- os .environ ['SOURCE_DATE_EPOCH' ] = sde
134
+ print ("Timestamp keyword (%s) not found!" % keyword )
135
+ assert string in buff
136
+ os .unlink (filename )
0 commit comments