Commits

Anonymous committed 1634f60

Exercise some error conditions

  • Participants
  • Parent commits 201986d
  • Branches legacy-trunk

Comments (0)

Files changed (1)

File Lib/test/test_heapq.py

         # 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):
             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 = []
                 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):