]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Test exceptional conditions in list.sort()
authorNeal Norwitz <nnorwitz@gmail.com>
Thu, 13 Jun 2002 22:23:06 +0000 (22:23 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Thu, 13 Jun 2002 22:23:06 +0000 (22:23 +0000)
Lib/test/test_types.py

index 71e18c4bbd3daad7f29546437b2883ebb14228c0..7f3b9233638f2d93320cc7a1788b8725939c96c3 100644 (file)
@@ -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]: