Show More
@@ -2618,7 +2618,12 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2618 | ns = self.user_ns.copy() |
|
2618 | ns = self.user_ns.copy() | |
2619 | ns.update(sys._getframe(depth+1).f_locals) |
|
2619 | ns.update(sys._getframe(depth+1).f_locals) | |
2620 | ns.pop('self', None) |
|
2620 | ns.pop('self', None) | |
2621 | return formatter.format(cmd, **ns) |
|
2621 | try: | |
|
2622 | cmd = formatter.format(cmd, **ns) | |||
|
2623 | except Exception: | |||
|
2624 | # if formatter couldn't format, just let it go untransformed | |||
|
2625 | pass | |||
|
2626 | return cmd | |||
2622 |
|
2627 | |||
2623 | def mktempfile(self, data=None, prefix='ipython_edit_'): |
|
2628 | def mktempfile(self, data=None, prefix='ipython_edit_'): | |
2624 | """Make a new tempfile and return its filename. |
|
2629 | """Make a new tempfile and return its filename. |
@@ -236,10 +236,24 b' class InteractiveShellTestCase(unittest.TestCase):' | |||||
236 | ip = get_ipython() |
|
236 | ip = get_ipython() | |
237 | ip.user_ns['f'] = u'Ca\xf1o' |
|
237 | ip.user_ns['f'] = u'Ca\xf1o' | |
238 | 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}'), u'echo Ca\xf1o') | |||
|
240 | self.assertEqual(ip.var_expand(u'echo {f[:-1]}'), u'echo Ca\xf1') | |||
|
241 | self.assertEqual(ip.var_expand(u'echo {1*2}'), u'echo 2') | |||
239 |
|
242 | |||
240 | ip.user_ns['f'] = b'Ca\xc3\xb1o' |
|
243 | ip.user_ns['f'] = b'Ca\xc3\xb1o' | |
241 | # This should not raise any exception: |
|
244 | # This should not raise any exception: | |
242 | ip.var_expand(u'echo $f') |
|
245 | ip.var_expand(u'echo $f') | |
|
246 | ||||
|
247 | def test_bad_var_expand(self): | |||
|
248 | """var_expand on invalid formats shouldn't raise""" | |||
|
249 | ip = get_ipython() | |||
|
250 | ||||
|
251 | # SyntaxError | |||
|
252 | self.assertEqual(ip.var_expand(u"{'a':5}"), u"{'a':5}") | |||
|
253 | # NameError | |||
|
254 | self.assertEqual(ip.var_expand(u"{asdf}"), u"{asdf}") | |||
|
255 | # ZeroDivisionError | |||
|
256 | self.assertEqual(ip.var_expand(u"{1/0}"), u"{1/0}") | |||
243 |
|
257 | |||
244 |
|
258 | |||
245 | class TestSafeExecfileNonAsciiPath(unittest.TestCase): |
|
259 | class TestSafeExecfileNonAsciiPath(unittest.TestCase): |
General Comments 0
You need to be logged in to leave comments.
Login now