summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sort.py
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/test_sort.py
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/test_sort.py')
-rw-r--r--Lib/test/test_sort.py29
1 files changed, 29 insertions, 0 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: