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