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

Skip to content

Commit 6ee8967

Browse files
author
Alexis Bienvenüe
committed
Add some insight when test_source_date_epoch fails.
1 parent 2a6ebc8 commit 6ee8967

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/matplotlib/testing/determinism.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io
66
import os
7+
import re
78

89
from matplotlib import pyplot as plt
910

@@ -93,7 +94,7 @@ def _test_determinism(objects='mhi', format="pdf"):
9394
assert_equal(p, plots[0])
9495

9596

96-
def _test_source_date_epoch(format, string):
97+
def _test_source_date_epoch(format, string, keyword=b"CreationDate"):
9798
"""
9899
Test SOURCE_DATE_EPOCH support. Output a document with the envionment
99100
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):
106107
format string, such as "pdf".
107108
string : str
108109
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).
109113
"""
110114
try:
111115
# save current value of SOURCE_DATE_EPOCH
@@ -115,10 +119,16 @@ def _test_source_date_epoch(format, string):
115119
x = [1, 2, 3, 4, 5]
116120
ax.plot(x, x)
117121
os.environ['SOURCE_DATE_EPOCH'] = "946684800"
122+
find_keyword = re.compile(b".*" + keyword + b".*")
118123
with io.BytesIO() as output:
119124
fig.savefig(output, format=format)
120125
output.seek(0)
121126
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)
122132
assert string in buff
123133
os.environ.pop('SOURCE_DATE_EPOCH', None)
124134
with io.BytesIO() as output:

0 commit comments

Comments
 (0)