##// END OF EJS Templates
Adding test for safe_execfile call with non-ascii path
Jörgen Stenarson -
Show More
@@ -2257,8 +2257,12 b' class InteractiveShell(SingletonConfigurable, Magic):'
2257 exit_ignore : bool (False)
2257 exit_ignore : bool (False)
2258 If True, then silence SystemExit for non-zero status (it is always
2258 If True, then silence SystemExit for non-zero status (it is always
2259 silenced for zero status, as it is so common).
2259 silenced for zero status, as it is so common).
2260 raise_exceptions : bool (False)
2261 If True raise exceptions everywhere. Meant for testing.
2262
2260 """
2263 """
2261 kw.setdefault('exit_ignore', False)
2264 kw.setdefault('exit_ignore', False)
2265 kw.setdefault('raise_exceptions', False)
2262
2266
2263 fname = os.path.abspath(os.path.expanduser(fname))
2267 fname = os.path.abspath(os.path.expanduser(fname))
2264
2268
@@ -2288,9 +2292,13 b' class InteractiveShell(SingletonConfigurable, Magic):'
2288 # 0
2292 # 0
2289 # For other exit status, we show the exception unless
2293 # For other exit status, we show the exception unless
2290 # explicitly silenced, but only in short form.
2294 # explicitly silenced, but only in short form.
2295 if kw['raise_exceptions']:
2296 raise
2291 if status.code not in (0, None) and not kw['exit_ignore']:
2297 if status.code not in (0, None) and not kw['exit_ignore']:
2292 self.showtraceback(exception_only=True)
2298 self.showtraceback(exception_only=True)
2293 except:
2299 except:
2300 if kw['raise_exceptions']:
2301 raise
2294 self.showtraceback()
2302 self.showtraceback()
2295
2303
2296 def safe_execfile_ipy(self, fname):
2304 def safe_execfile_ipy(self, fname):
@@ -1,3 +1,4 b''
1 # -*- coding: utf-8 -*-
1 """Tests for the key interactiveshell module.
2 """Tests for the key interactiveshell module.
2
3
3 Historically the main classes in interactiveshell have been under-tested. This
4 Historically the main classes in interactiveshell have been under-tested. This
@@ -19,7 +20,11 b' Authors'
19 # Imports
20 # Imports
20 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
21 # stdlib
22 # stdlib
23 import os
24 import shutil
25 import tempfile
22 import unittest
26 import unittest
27 from os.path import join
23 from StringIO import StringIO
28 from StringIO import StringIO
24
29
25 from IPython.testing import decorators as dec
30 from IPython.testing import decorators as dec
@@ -193,3 +198,25 b' class InteractiveShellTestCase(unittest.TestCase):'
193 assert name not in ip.user_ns_hidden, name
198 assert name not in ip.user_ns_hidden, name
194 assert ip.user_ns['b'] == 12
199 assert ip.user_ns['b'] == 12
195 ip.reset()
200 ip.reset()
201
202 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
203
204 def setUp(self):
205 self.BASETESTDIR = tempfile.mkdtemp()
206 self.TESTDIR = join(self.BASETESTDIR, u"åäö")
207 os.mkdir(self.TESTDIR)
208 with open(join(self.TESTDIR, u"åäötestscript.py"), "w") as sfile:
209 sfile.write("pass\n")
210 self.oldpath = os.getcwdu()
211 os.chdir(self.TESTDIR)
212 self.fname = u"åäötestscript.py"
213
214
215 def tearDown(self):
216 os.chdir(self.oldpath)
217 shutil.rmtree(self.BASETESTDIR)
218
219 def test_1(self):
220 """Test safe_execfile with non-ascii path
221 """
222 _ip.shell.safe_execfile(self.fname, raise_exceptions=True)
@@ -153,7 +153,7 b' else:'
153 return s.format(u='u')
153 return s.format(u='u')
154
154
155 if sys.platform == 'win32':
155 if sys.platform == 'win32':
156 def execfile(fname, glob, loc=None):
156 def execfile(fname, glob=None, loc=None):
157 loc = loc if (loc is not None) else glob
157 loc = loc if (loc is not None) else glob
158 scripttext = __builtin__.open(fname).read()
158 scripttext = __builtin__.open(fname).read()
159 #compile converts unicode filename to str assuming
159 #compile converts unicode filename to str assuming
@@ -164,7 +164,7 b' else:'
164 filename = fname
164 filename = fname
165 exec compile(scripttext, filename, 'exec') in glob, loc
165 exec compile(scripttext, filename, 'exec') in glob, loc
166 else:
166 else:
167 def execfile(fname, glob, loc=None):
167 def execfile(fname, glob=None, loc=None):
168 if isinstance(fname, unicode):
168 if isinstance(fname, unicode):
169 filename = fname.encode(sys.getfilesystemencoding())
169 filename = fname.encode(sys.getfilesystemencoding())
170 else:
170 else:
General Comments 0
You need to be logged in to leave comments. Login now