summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-03-05 07:16:45 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-03-05 07:16:45 (GMT)
commit757408a2f3f52a253bdd52de07b8e9a1e9e73384 (patch)
tree73b96f7e082351154bf5b289a7e216140dfcdf5e /Lib
parent3e6aafe20993f5b3690c870bf88eed3d8ba53492 (diff)
parenteec152d21783b901efae86afde771995fb357136 (diff)
downloadcpython-757408a2f3f52a253bdd52de07b8e9a1e9e73384.zip
cpython-757408a2f3f52a253bdd52de07b8e9a1e9e73384.tar.gz
cpython-757408a2f3f52a253bdd52de07b8e9a1e9e73384.tar.bz2
merge
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/pickletester.py4
-rw-r--r--Lib/test/test_exceptions.py12
-rw-r--r--Lib/test/test_heapq.py26
-rw-r--r--Lib/test/test_posixpath.py1
4 files changed, 41 insertions, 2 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index f735e95..3e7e11d 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -503,10 +503,10 @@ class AbstractPickleTests(unittest.TestCase):
i = C()
i.attr = i
for proto in protocols:
- s = self.dumps(i, 2)
+ s = self.dumps(i, proto)
x = self.loads(s)
self.assertEqual(dir(x), dir(i))
- self.assertTrue(x.attr is x)
+ self.assertIs(x.attr, x)
def test_recursive_multi(self):
l = []
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 2160641..a485cba 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -479,6 +479,18 @@ class ExceptionTests(unittest.TestCase):
except AssertionError as e:
self.assertEqual(str(e), "(3,)")
+ def test_bad_exception_clearing(self):
+ # See issue 16445: use of Py_XDECREF instead of Py_CLEAR in
+ # BaseException_set_message gave a possible way to segfault the
+ # interpreter.
+ class Nasty(str):
+ def __del__(message):
+ del e.message
+
+ e = ValueError(Nasty("msg"))
+ e.args = ()
+ del e.message
+
# Helper class used by TestSameStrAndUnicodeMsg
class ExcWithOverriddenStr(Exception):
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index 5932a40..73b88f0 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -315,6 +315,16 @@ def L(seqn):
'Test multiple tiers of iterators'
return chain(imap(lambda x:x, R(Ig(G(seqn)))))
+class SideEffectLT:
+ def __init__(self, value, heap):
+ self.value = value
+ self.heap = heap
+
+ def __lt__(self, other):
+ self.heap[:] = []
+ return self.value < other.value
+
+
class TestErrorHandling(TestCase):
module = None
@@ -361,6 +371,22 @@ class TestErrorHandling(TestCase):
self.assertRaises(TypeError, f, 2, N(s))
self.assertRaises(ZeroDivisionError, f, 2, E(s))
+ # Issue #17278: the heap may change size while it's being walked.
+
+ def test_heappush_mutating_heap(self):
+ heap = []
+ heap.extend(SideEffectLT(i, heap) for i in range(200))
+ # Python version raises IndexError, C version RuntimeError
+ with self.assertRaises((IndexError, RuntimeError)):
+ self.module.heappush(heap, SideEffectLT(5, heap))
+
+ def test_heappop_mutating_heap(self):
+ heap = []
+ heap.extend(SideEffectLT(i, heap) for i in range(200))
+ # Python version raises IndexError, C version RuntimeError
+ with self.assertRaises((IndexError, RuntimeError)):
+ self.module.heappop(heap)
+
class TestErrorHandlingPython(TestErrorHandling):
module = py_heapq
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index d9867a6..f74dc14 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -284,6 +284,7 @@ class PosixPathTest(unittest.TestCase):
test_support.unlink(ABSTFN+"2")
test_support.unlink(ABSTFN+"y")
test_support.unlink(ABSTFN+"c")
+ test_support.unlink(ABSTFN+"a")
def test_realpath_repeated_indirect_symlinks(self):
# Issue #6975.