##// END OF EJS Templates
ignore errors in shell.var_expand...
MinRK -
Show More
@@ -2675,7 +2675,12 b' class InteractiveShell(SingletonConfigurable, Magic):'
2675 ns = self.user_ns.copy()
2675 ns = self.user_ns.copy()
2676 ns.update(sys._getframe(depth+1).f_locals)
2676 ns.update(sys._getframe(depth+1).f_locals)
2677 ns.pop('self', None)
2677 ns.pop('self', None)
2678 return formatter.format(cmd, **ns)
2678 try:
2679 cmd = formatter.format(cmd, **ns)
2680 except Exception:
2681 # if formatter couldn't format, just let it go untransformed
2682 pass
2683 return cmd
2679
2684
2680 def mktempfile(self, data=None, prefix='ipython_edit_'):
2685 def mktempfile(self, data=None, prefix='ipython_edit_'):
2681 """Make a new tempfile and return its filename.
2686 """Make a new tempfile and return its filename.
@@ -235,10 +235,24 b' class InteractiveShellTestCase(unittest.TestCase):'
235 ip = get_ipython()
235 ip = get_ipython()
236 ip.user_ns['f'] = u'Ca\xf1o'
236 ip.user_ns['f'] = u'Ca\xf1o'
237 self.assertEqual(ip.var_expand(u'echo $f'), u'echo Ca\xf1o')
237 self.assertEqual(ip.var_expand(u'echo $f'), u'echo Ca\xf1o')
238 self.assertEqual(ip.var_expand(u'echo {f}'), u'echo Ca\xf1o')
239 self.assertEqual(ip.var_expand(u'echo {f[:-1]}'), u'echo Ca\xf1')
240 self.assertEqual(ip.var_expand(u'echo {1*2}'), u'echo 2')
238
241
239 ip.user_ns['f'] = b'Ca\xc3\xb1o'
242 ip.user_ns['f'] = b'Ca\xc3\xb1o'
240 # This should not raise any exception:
243 # This should not raise any exception:
241 ip.var_expand(u'echo $f')
244 ip.var_expand(u'echo $f')
245
246 def test_bad_var_expand(self):
247 """var_expand on invalid formats shouldn't raise"""
248 ip = get_ipython()
249
250 # SyntaxError
251 self.assertEqual(ip.var_expand(u"{'a':5}"), u"{'a':5}")
252 # NameError
253 self.assertEqual(ip.var_expand(u"{asdf}"), u"{asdf}")
254 # ZeroDivisionError
255 self.assertEqual(ip.var_expand(u"{1/0}"), u"{1/0}")
242
256
243
257
244 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
258 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
General Comments 0
You need to be logged in to leave comments. Login now