diff options
Diffstat (limited to 'Lib/test/test_heapq.py')
| -rw-r--r-- | Lib/test/test_heapq.py | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 20fb89c..b5a2fd8 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -2,6 +2,7 @@ import sys import random +import unittest from test import support from unittest import TestCase, skipUnless @@ -25,8 +26,7 @@ class TestModules(TestCase): self.assertEqual(getattr(c_heapq, fname).__module__, '_heapq') -class TestHeap(TestCase): - module = None +class TestHeap: def test_push_pop(self): # 1) Push 256 random numbers and pop them off, verifying all's OK. @@ -158,6 +158,15 @@ class TestHeap(TestCase): self.assertEqual(sorted(chain(*inputs)), list(self.module.merge(*inputs))) self.assertEqual(list(self.module.merge()), []) + def test_merge_does_not_suppress_index_error(self): + # Issue 19018: Heapq.merge suppresses IndexError from user generator + def iterable(): + s = list(range(10)) + for i in range(20): + yield s[i] # IndexError when i > 10 + with self.assertRaises(IndexError): + list(self.module.merge(iterable(), iterable())) + def test_merge_stability(self): class Int(int): pass @@ -214,12 +223,12 @@ class TestHeap(TestCase): self.assertRaises(TypeError, data, LE) -class TestHeapPython(TestHeap): +class TestHeapPython(TestHeap, TestCase): module = py_heapq @skipUnless(c_heapq, 'requires _heapq') -class TestHeapC(TestHeap): +class TestHeapC(TestHeap, TestCase): module = c_heapq @@ -329,8 +338,7 @@ class SideEffectLT: return self.value < other.value -class TestErrorHandling(TestCase): - module = None +class TestErrorHandling: def test_non_sequence(self): for f in (self.module.heapify, self.module.heappop): @@ -397,31 +405,13 @@ class TestErrorHandling(TestCase): self.module.heappop(heap) -class TestErrorHandlingPython(TestErrorHandling): +class TestErrorHandlingPython(TestErrorHandling, TestCase): module = py_heapq @skipUnless(c_heapq, 'requires _heapq') -class TestErrorHandlingC(TestErrorHandling): +class TestErrorHandlingC(TestErrorHandling, TestCase): module = c_heapq -#============================================================================== - - -def test_main(verbose=None): - test_classes = [TestModules, TestHeapPython, TestHeapC, - TestErrorHandlingPython, TestErrorHandlingC] - support.run_unittest(*test_classes) - - # verify reference counting - if verbose and hasattr(sys, "gettotalrefcount"): - import gc - counts = [None] * 5 - for i in range(len(counts)): - support.run_unittest(*test_classes) - gc.collect() - counts[i] = sys.gettotalrefcount() - print(counts) - if __name__ == "__main__": - test_main(verbose=True) + unittest.main() |
