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 df9204b

Browse filesBrowse files
committed
TST: add a test for tilde in tempfile for the PS backend
The PS uses latex in some cases (usetex=True) and latex does not like to be called with dirnames with ~ in it (reserved char). The Fix for that was in #5928, this is just a testcase to test for the fix.
1 parent 7b517da commit df9204b
Copy full SHA for df9204b

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
@@ -134,6 +134,46 @@ def test_patheffects():
134134
fig.savefig(ps, format='ps')
135135

136136

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