blob: 3a9a37934c3fa47fdc555e5408a23c21f57622c4 [file] [log] [blame]
Guido van Rossum3bead091992-01-27 17:00:37 +00001# Python test set -- part 3, built-in operations.
2
3
4print '3. Operations'
Fred Drake762c1cb2000-08-31 19:48:52 +00005print 'XXX Mostly not yet implemented'
6
7
8print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception'
9
10# SourceForge bug #112558:
11# http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470
12
Fred Drake004d5e62000-10-23 17:22:08 +000013class BadDictKey:
14 def __hash__(self):
15 return hash(self.__class__)
Fred Drake762c1cb2000-08-31 19:48:52 +000016
Fred Drake004d5e62000-10-23 17:22:08 +000017 def __cmp__(self, other):
18 if isinstance(other, self.__class__):
19 print "raising error"
20 raise RuntimeError, "gotcha"
21 return other
Fred Drake762c1cb2000-08-31 19:48:52 +000022
23d = {}
24x1 = BadDictKey()
25x2 = BadDictKey()
26d[x1] = 1
27d[x2] = 2
28print "No exception passed through."
Tim Peters0c6010b2001-05-23 23:33:57 +000029
30# Dict resizing bug, found by Jack Jansen in 2.2 CVS development.
31# This version got an assert failure in debug build, infinite loop in
32# release build. Unfortunately, provoking this kind of stuff requires
33# a mix of inserts and deletes hitting exactly the right hash codes in
34# exactly the right order, and I can't think of a randomized approach
35# that would be *likely* to hit a failing case in reasonable time.
36
37d = {}
38for i in range(5):
39 d[i] = i
40for i in range(5):
41 del d[i]
42for i in range(5, 9): # i==8 was the problem
43 d[i] = i