##// END OF EJS Templates
Catch errors raised by user objects when accessing attributes....
Fernando Perez -
Show More
@@ -812,7 +812,14 b' class AutoHandler(PrefilterHandler):'
812 return line
812 return line
813
813
814 force_auto = isinstance(obj, IPyAutocall)
814 force_auto = isinstance(obj, IPyAutocall)
815 auto_rewrite = getattr(obj, 'rewrite', True)
815
816 # User objects sometimes raise exceptions on attribute access other
817 # than AttributeError (we've seen it in the past), so it's safest to be
818 # ultra-conservative here and catch all.
819 try:
820 auto_rewrite = obj.rewrite
821 except Exception:
822 auto_rewrite = True
816
823
817 if esc == ESC_QUOTE:
824 if esc == ESC_QUOTE:
818 # Auto-quote splitting on whitespace
825 # Auto-quote splitting on whitespace
@@ -35,6 +35,7 b' def test_prefilter():'
35 for raw, correct in pairs:
35 for raw, correct in pairs:
36 yield nt.assert_equals(ip.prefilter(raw), correct)
36 yield nt.assert_equals(ip.prefilter(raw), correct)
37
37
38
38 @dec.parametric
39 @dec.parametric
39 def test_autocall_binops():
40 def test_autocall_binops():
40 """See https://github.com/ipython/ipython/issues/81"""
41 """See https://github.com/ipython/ipython/issues/81"""
@@ -49,10 +50,11 b' def test_autocall_binops():'
49 ip.magic('autocall 0')
50 ip.magic('autocall 0')
50 del ip.user_ns['f']
51 del ip.user_ns['f']
51
52
53
52 @dec.parametric
54 @dec.parametric
53 def test_issue114():
55 def test_issue_114():
54 """Check that multiline string literals don't expand as magic
56 """Check that multiline string literals don't expand as magic
55 see http://github.com/ipython/ipython/issues/#issue/114"""
57 see http://github.com/ipython/ipython/issues/114"""
56
58
57 template = '"""\n%s\n"""'
59 template = '"""\n%s\n"""'
58 # Store the current value of multi_line_specials and turn it off before
60 # Store the current value of multi_line_specials and turn it off before
@@ -66,3 +68,27 b' def test_issue114():'
66 yield nt.assert_equals(ip.prefilter(raw), raw)
68 yield nt.assert_equals(ip.prefilter(raw), raw)
67 finally:
69 finally:
68 ip.prefilter_manager.multi_line_specials = msp
70 ip.prefilter_manager.multi_line_specials = msp
71
72
73 def test_prefilter_attribute_errors():
74 """Capture exceptions thrown by user objects on attribute access.
75
76 See http://github.com/ipython/ipython/issues/988."""
77
78 class X(object):
79 def __getattr__(self, k):
80 raise ValueError('broken object')
81 def __call__(self, x):
82 return x
83
84 # Create a callable broken object
85 ip.user_ns['x'] = X()
86 ip.magic('autocall 2')
87 try:
88 # Even if x throws an attribute error when looking at its rewrite
89 # attribute, we should not crash. So the test here is simply making
90 # the prefilter call and not having an exception.
91 ip.prefilter('x 1')
92 finally:
93 del ip.user_ns['x']
94 ip.magic('autocall 0')
General Comments 0
You need to be logged in to leave comments. Login now