summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-11-12 22:08:10 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-11-12 22:08:10 (GMT)
commitb9099c3df495d4bf0090d7a751325343852b61db (patch)
tree02605a750bc4b07c663d01ee61cc75755ab26c67 /Lib/test
parent4b9ed2f346921353b34a99332d9efd6ddce3a28b (diff)
downloadcpython-b9099c3df495d4bf0090d7a751325343852b61db.zip
cpython-b9099c3df495d4bf0090d7a751325343852b61db.tar.gz
cpython-b9099c3df495d4bf0090d7a751325343852b61db.tar.bz2
SF patch 637176: list.sort crasher
Armin Rigo's Draconian but effective fix for SF bug 453523: list.sort crasher slightly fiddled to catch more cases of list mutation. The dreaded internal "immutable list type" is gone! OTOH, if you look at a list *while* it's being sorted now, it will appear to be empty. Better than a core dump.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_sort.py29
-rw-r--r--Lib/test/test_types.py4
2 files changed, 31 insertions, 2 deletions
diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py
index 9b31052..5c7ae88 100644
--- a/Lib/test/test_sort.py
+++ b/Lib/test/test_sort.py
@@ -116,6 +116,35 @@ for n in sizes:
x = [e for e, i in augmented] # a stable sort of s
check("stability", x, s)
+def bug453523():
+ global nerrors
+ from random import random
+
+ # If this fails, the most likely outcome is a core dump.
+ if verbose:
+ print "Testing bug 453523 -- list.sort() crasher."
+
+ class C:
+ def __lt__(self, other):
+ if L and random() < 0.75:
+ pop()
+ else:
+ push(3)
+ return random() < 0.5
+
+ L = [C() for i in range(50)]
+ pop = L.pop
+ push = L.append
+ try:
+ L.sort()
+ except ValueError:
+ pass
+ else:
+ print " Mutation during list.sort() wasn't caught."
+ nerrors += 1
+
+bug453523()
+
if nerrors:
print "Test failed", nerrors
elif verbose:
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 9777e83..d075d94 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -367,10 +367,10 @@ except TypeError: pass
else: raise TestFailed, 'list sort compare function is not callable'
def selfmodifyingComparison(x,y):
- z[0] = 1
+ z.append(1)
return cmp(x, y)
try: z.sort(selfmodifyingComparison)
-except TypeError: pass
+except ValueError: pass
else: raise TestFailed, 'modifying list during sort'
try: z.sort(lambda x, y: 's')