@@ -132,6 +132,46 @@ def test_patheffects():
132
132
fig .savefig (ps , format = 'ps' )
133
133
134
134
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
+
135
175
if __name__ == '__main__' :
136
176
import nose
137
177
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments