4
4
5
5
import io
6
6
import os
7
+ import re
7
8
8
9
from matplotlib import pyplot as plt
9
10
@@ -93,7 +94,7 @@ def _test_determinism(objects='mhi', format="pdf"):
93
94
assert_equal (p , plots [0 ])
94
95
95
96
96
- def _test_source_date_epoch (format , string ):
97
+ def _test_source_date_epoch (format , string , keyword = b"CreationDate" ):
97
98
"""
98
99
Test SOURCE_DATE_EPOCH support. Output a document with the envionment
99
100
variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
@@ -106,6 +107,9 @@ def _test_source_date_epoch(format, string):
106
107
format string, such as "pdf".
107
108
string : str
108
109
timestamp string for 2000-01-01 00:00 UTC.
110
+ keyword : str
111
+ a string to look at when searching for the timestamp in the document
112
+ (used in case the test fails).
109
113
"""
110
114
try :
111
115
# save current value of SOURCE_DATE_EPOCH
@@ -115,10 +119,16 @@ def _test_source_date_epoch(format, string):
115
119
x = [1 , 2 , 3 , 4 , 5 ]
116
120
ax .plot (x , x )
117
121
os .environ ['SOURCE_DATE_EPOCH' ] = "946684800"
122
+ find_keyword = re .compile (b".*" + keyword + b".*" )
118
123
with io .BytesIO () as output :
119
124
fig .savefig (output , format = format )
120
125
output .seek (0 )
121
126
buff = output .read ()
127
+ key = find_keyword .search (buff )
128
+ if key :
129
+ print (key .group ())
130
+ else :
131
+ print ("Timestamp keyword (%s) not found!" % keyword )
122
132
assert string in buff
123
133
os .environ .pop ('SOURCE_DATE_EPOCH' , None )
124
134
with io .BytesIO () as output :
0 commit comments