Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6fc36c5

Browse files
committed
Test exceptional conditions in list.sort()
1 parent 2b34290 commit 6fc36c5

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_types.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,21 @@ def myComparison(x,y):
353353
z = range(12)
354354
z.sort(myComparison)
355355

356+
try: z.sort(2)
357+
except TypeError: pass
358+
else: raise TestFailed, 'list sort compare function is not callable'
359+
360+
def selfmodifyingComparison(x,y):
361+
z[0] = 1
362+
return cmp(x, y)
363+
try: z.sort(selfmodifyingComparison)
364+
except TypeError: pass
365+
else: raise TestFailed, 'modifying list during sort'
366+
367+
try: z.sort(lambda x, y: 's')
368+
except TypeError: pass
369+
else: raise TestFailed, 'list sort compare function does not return int'
370+
356371
# Test extreme cases with long ints
357372
a = [0,1,2,3,4]
358373
if a[ -pow(2,128L): 3 ] != [0,1,2]:

0 commit comments

Comments
 (0)