summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_heapq.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2004-07-08 01:56:46 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2004-07-08 01:56:46 (GMT)
commitd7be118626386ffd0f98efc3518855aa8654c6bd (patch)
tree312fe065ef58d407d5ca883b3006cf393babb806 /Lib/test/test_heapq.py
parent739a8f86d6b4df7a36ec875660095ff16aa560d7 (diff)
downloadcpython-d7be118626386ffd0f98efc3518855aa8654c6bd.zip
cpython-d7be118626386ffd0f98efc3518855aa8654c6bd.tar.gz
cpython-d7be118626386ffd0f98efc3518855aa8654c6bd.tar.bz2
Exercise some error conditions
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r--Lib/test/test_heapq.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index 4e535e9..f37d8ff 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -38,6 +38,10 @@ class TestHeap(unittest.TestCase):
# 2) Check that the invariant holds for a sorted array
self.check_invariant(results)
+ self.assertRaises(TypeError, heappush, [])
+ self.assertRaises(TypeError, heappush, None, None)
+ self.assertRaises(TypeError, heappop, None)
+
def check_invariant(self, heap):
# Check the heap invariant.
for pos, item in enumerate(heap):
@@ -51,6 +55,8 @@ class TestHeap(unittest.TestCase):
heapify(heap)
self.check_invariant(heap)
+ self.assertRaises(TypeError, heapify, None)
+
def test_naive_nbest(self):
data = [random.randrange(2000) for i in range(1000)]
heap = []
@@ -75,6 +81,10 @@ class TestHeap(unittest.TestCase):
heapreplace(heap, item)
self.assertEqual(list(heapiter(heap)), sorted(data)[-10:])
+ self.assertRaises(TypeError, heapreplace, None)
+ self.assertRaises(TypeError, heapreplace, None, None)
+ self.assertRaises(IndexError, heapreplace, [], None)
+
def test_heapsort(self):
# Exercise everything with repeated heapsort checks
for trial in xrange(100):