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

Appearance settings

Commit a25bcbf

Browse filesBrowse files
committed
Merge pull request #5958 from JanSchulz/tilde-in-temp
TST: add a test for tilde in tempfile for the PS backend
1 parent ab7c982 commit a25bcbf
Copy full SHA for a25bcbf

File tree

Expand file treeCollapse file tree

1 file changed

+40
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+40
-0
lines changed

‎lib/matplotlib/tests/test_backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_ps.py
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,46 @@ def test_patheffects():
132132
fig.savefig(ps, format='ps')
133133

134134

135+
@cleanup
136+
@needs_tex
137+
@needs_ghostscript
138+
def test_tilde_in_tempfilename():
139+
# Tilde ~ in the tempdir path (e.g. TMPDIR, TMP oder TEMP on windows
140+
# when the username is very long and windows uses a short name) breaks
141+
# latex before https://github.com/matplotlib/matplotlib/pull/5928
142+
import tempfile
143+
import shutil
144+
import os
145+
import os.path
146+
147+
tempdir = None
148+
old_tempdir = tempfile.tempdir
149+
try:
150+
# change the path for new tempdirs, which is used
151+
# internally by the ps backend to write a file
152+
tempdir = tempfile.mkdtemp()
153+
base_tempdir = os.path.join(tempdir, "short~1")
154+
os.makedirs(base_tempdir)
155+
tempfile.tempdir = base_tempdir
156+
157+
# usetex results in the latex call, which does not like the ~
158+
plt.rc('text', usetex=True)
159+
plt.plot([1, 2, 3, 4])
160+
plt.xlabel(r'\textbf{time} (s)')
161+
#matplotlib.verbose.set_level("debug")
162+
output_eps = os.path.join(base_tempdir, 'tex_demo.eps')
163+
# use the PS backend to write the file...
164+
plt.savefig(output_eps, format="ps")
165+
finally:
166+
tempfile.tempdir = old_tempdir
167+
if tempdir:
168+
try:
169+
shutil.rmtree(tempdir)
170+
except Exception as e:
171+
# do not break if this is not removeable...
172+
print(e)
173+
174+
135175
if __name__ == '__main__':
136176
import nose
137177
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.