PageRenderTime 92ms CodeModel.GetById 50ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/Lib/test/crashers/iter.py

http://unladen-swallow.googlecode.com/
Python | 53 lines | 31 code | 14 blank | 8 comment | 2 complexity | 4822008d5b6240b83e1ecdce8ea4ec0a MD5 | raw file
 1# Calls to PyIter_Next, or direct calls to tp_iternext, on an object
 2# which might no longer be an iterable because its 'next' method was
 3# removed.  These are all variants of Issue3720.
 4
 5"""
 6Run this script with an argument between 1 and <N> to test for
 7different crashes.
 8"""
 9N = 8
10
11import sys
12
13class Foo(object):
14    def __iter__(self):
15        return self
16    def next(self):
17        del Foo.next
18        return (1, 2)
19
20def case1():
21    list(enumerate(Foo()))
22
23def case2():
24    x, y = Foo()
25
26def case3():
27    filter(None, Foo())
28
29def case4():
30    map(None, Foo(), Foo())
31
32def case5():
33    max(Foo())
34
35def case6():
36    sum(Foo(), ())
37
38def case7():
39    dict(Foo())
40
41def case8():
42    sys.stdout.writelines(Foo())
43
44# etc...
45
46
47if __name__ == '__main__':
48    if len(sys.argv) < 2:
49        print __doc__.replace('<N>', str(N))
50    else:
51        n = int(sys.argv[1])
52        func = globals()['case%d' % n]
53        func()