mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Test exceptional conditions in list.sort()
This commit is contained in:
parent
2b34290055
commit
6fc36c5491
1 changed files with 15 additions and 0 deletions
|
@ -353,6 +353,21 @@ def myComparison(x,y):
|
|||
z = range(12)
|
||||
z.sort(myComparison)
|
||||
|
||||
try: z.sort(2)
|
||||
except TypeError: pass
|
||||
else: raise TestFailed, 'list sort compare function is not callable'
|
||||
|
||||
def selfmodifyingComparison(x,y):
|
||||
z[0] = 1
|
||||
return cmp(x, y)
|
||||
try: z.sort(selfmodifyingComparison)
|
||||
except TypeError: pass
|
||||
else: raise TestFailed, 'modifying list during sort'
|
||||
|
||||
try: z.sort(lambda x, y: 's')
|
||||
except TypeError: pass
|
||||
else: raise TestFailed, 'list sort compare function does not return int'
|
||||
|
||||
# Test extreme cases with long ints
|
||||
a = [0,1,2,3,4]
|
||||
if a[ -pow(2,128L): 3 ] != [0,1,2]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue