##// END OF EJS Templates
Add test for infinite looping on attribute access
Thomas Kluyver -
Show More
@@ -186,6 +186,23 b' class NoBoolCall:'
186 186 raise NotImplementedError('Must be implemented')
187 187
188 188
189 class SerialLiar(object):
190 """Attribute accesses always get another copy of the same class.
191
192 unittest.mock.call does something similar, but it's not ideal for testing
193 as the failure mode is to eat all your RAM. This gives up after 10k levels.
194 """
195 def __init__(self, max_fibbing_twig, lies_told=0):
196 if lies_told > 10000:
197 raise RuntimeError('Nose too long, honesty is the best policy')
198 self.max_fibbing_twig = max_fibbing_twig
199 self.lies_told = lies_told
200 max_fibbing_twig[0] = max(max_fibbing_twig[0], lies_told)
201
202 def __getattr__(self, item):
203 return SerialLiar(self.max_fibbing_twig, self.lies_told + 1)
204
205
189 206 def check_calltip(obj, name, call, docstring):
190 207 """Generic check pattern all calltip tests will use"""
191 208 info = inspector.info(obj, name)
@@ -297,6 +314,14 b' def test_info_awkward():'
297 314 def test_bool_raise():
298 315 inspector.info(NoBoolCall())
299 316
317 def test_info_serialliar():
318 fib_tracker = [0]
319 i = inspector.info(SerialLiar(fib_tracker))
320
321 # Nested attribute access should be cut off at 100 levels deep to avoid
322 # infinite loops: https://github.com/ipython/ipython/issues/9122
323 nt.assert_less(fib_tracker[0], 9000)
324
300 325 def test_calldef_none():
301 326 # We should ignore __call__ for all of these.
302 327 for obj in [f, SimpleClass().method, any, str.upper]:
General Comments 0
You need to be logged in to leave comments. Login now