Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6301c2

Browse files
author
JojoBoulix
authored
Merge pull request#1 from QuLogic/reproducible-master
Determinism tests without temporary files
2 parents995173d +ebff832 commitf6301c2

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

‎lib/matplotlib/testing/determinism.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
Provides utilities to test output reproducibility.
33
"""
44

5+
importsix
6+
57
importio
68
importos
79
importre
10+
importsys
11+
fromsubprocessimportcheck_output
812

913
frommatplotlibimportpyplotasplt
1014

1115

12-
def_determinism_save(filename,objects='mhi',format="pdf"):
16+
def_determinism_save(objects='mhi',format="pdf"):
1317
# save current value of SOURCE_DATE_EPOCH and set it
1418
# to a constant value, so that time difference is not
1519
# taken into account
@@ -51,7 +55,13 @@ def _determinism_save(filename, objects='mhi', format="pdf"):
5155
x=range(5)
5256
fig.add_subplot(1,6,6).plot(x,x)
5357

54-
fig.savefig(filename,format=format)
58+
ifsix.PY2andformat=='ps':
59+
stdout=io.StringIO()
60+
else:
61+
stdout=getattr(sys.stdout,'buffer',sys.stdout)
62+
fig.savefig(stdout,format=format)
63+
ifsix.PY2andformat=='ps':
64+
sys.stdout.write(stdout.getvalue())
5565

5666
# Restores SOURCE_DATE_EPOCH
5767
ifsdeisNone:
@@ -77,22 +87,17 @@ def _determinism_check(objects='mhi', format="pdf", uid=""):
7787
some string to add to the filename used to store the output. Use it to
7888
allow parallel execution of two tests with the same objects parameter.
7989
"""
80-
importsys
81-
fromsubprocessimportcheck_call
8290
fromnose.toolsimportassert_equal
83-
filename='determinism_O%s%s.%s'% (objects,uid,format)
8491
plots= []
8592
foriinrange(3):
86-
check_call([sys.executable,'-R','-c',
87-
'import matplotlib; '
88-
'matplotlib.use(%r); '
89-
'from matplotlib.testing.determinism '
90-
'import _determinism_save;'
91-
'_determinism_save(%r,%r,%r)'
92-
% (format,filename,objects,format)])
93-
withopen(filename,'rb')asfd:
94-
plots.append(fd.read())
95-
os.unlink(filename)
93+
result=check_output([sys.executable,'-R','-c',
94+
'import matplotlib; '
95+
'matplotlib.use(%r); '
96+
'from matplotlib.testing.determinism '
97+
'import _determinism_save;'
98+
'_determinism_save(%r,%r)'
99+
% (format,objects,format)])
100+
plots.append(result)
96101
forpinplots[1:]:
97102
assert_equal(p,plots[0])
98103

@@ -114,23 +119,17 @@ def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
114119
a string to look at when searching for the timestamp in the document
115120
(used in case the test fails).
116121
"""
117-
importsys
118-
fromsubprocessimportcheck_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 _determinism_save;'
125-
'_determinism_save(%r,%r,%r)'
126-
% (format,filename,"",format)])
122+
buff=check_output([sys.executable,'-R','-c',
123+
'import matplotlib; '
124+
'matplotlib.use(%r); '
125+
'from matplotlib.testing.determinism '
126+
'import _determinism_save;'
127+
'_determinism_save(%r,%r)'
128+
% (format,"",format)])
127129
find_keyword=re.compile(b".*"+keyword+b".*")
128-
withopen(filename,'rb')asfd:
129-
buff=fd.read()
130-
key=find_keyword.search(buff)
131-
ifkey:
132-
print(key.group())
133-
else:
134-
print("Timestamp keyword (%s) not found!"%keyword)
135-
assertstringinbuff
136-
os.unlink(filename)
130+
key=find_keyword.search(buff)
131+
ifkey:
132+
print(key.group())
133+
else:
134+
print("Timestamp keyword (%s) not found!"%keyword)
135+
assertstringinbuff

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp