diff options
author | Michael W. Hudson <mwh@python.net> | 2003-12-04 11:25:46 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2003-12-04 11:25:46 (GMT) |
commit | 1df0f654e845ef7c1252db10b88066691807be5b (patch) | |
tree | 69261072cb9f43e20ab635b8193f88c01ddcc391 /Lib/test | |
parent | c6c5ece7e2ece9ac5c4ba3b06a1d56b78cf74b27 (diff) | |
download | cpython-1df0f654e845ef7c1252db10b88066691807be5b.zip cpython-1df0f654e845ef7c1252db10b88066691807be5b.tar.gz cpython-1df0f654e845ef7c1252db10b88066691807be5b.tar.bz2 |
Fixes and tests for various "holding pointers when arbitrary Python code
can run" bugs as discussed in
[ 848856 ] couple of new list.sort bugs
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_sort.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py index 2659a90..74f3bb5 100644 --- a/Lib/test/test_sort.py +++ b/Lib/test/test_sort.py @@ -193,6 +193,51 @@ class TestDecorateSortUndecorate(unittest.TestCase): self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1/x) self.assertEqual(data, dup) + def test_key_with_mutation(self): + data = range(10) + def k(x): + del data[:] + data[:] = range(20) + return x + self.assertRaises(ValueError, data.sort, key=k) + + def test_key_with_mutating_del(self): + data = range(10) + class SortKiller(object): + def __init__(self, x): + pass + def __del__(self): + del data[:] + data[:] = range(20) + self.assertRaises(ValueError, data.sort, key=SortKiller) + + def test_key_with_mutating_del_and_exception(self): + data = range(10) + ## dup = data[:] + class SortKiller(object): + def __init__(self, x): + if x > 2: + raise RuntimeError + def __del__(self): + del data[:] + data[:] = range(20) + self.assertRaises(RuntimeError, data.sort, key=SortKiller) + ## major honking subtlety: we *can't* do: + ## + ## self.assertEqual(data, dup) + ## + ## because there is a reference to a SortKiller in the + ## traceback and by the time it dies we're outside the call to + ## .sort() and so the list protection gimmicks are out of + ## date (this cost some brain cells to figure out...). + + def test_key_with_exception(self): + # Verify that the wrapper has been removed + data = range(-2,2) + dup = data[:] + self.assertRaises(ZeroDivisionError, data.sort, None, lambda x: 1/x) + self.assertEqual(data, dup) + def test_reverse(self): data = range(100) random.shuffle(data) |