Skip to content

Commit b8b1667

Browse files
Improved tests
1 parent 31e1e3d commit b8b1667

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/test/test_heapq.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# Add max-heap variants
1818
func_names += [func + '_max' for func in func_names]
1919

20+
class_names = ['MinHeap', 'MaxHeap']
21+
2022
class TestModules(TestCase):
2123
def test_py_functions(self):
2224
for fname in func_names:
@@ -27,6 +29,15 @@ def test_c_functions(self):
2729
for fname in func_names:
2830
self.assertEqual(getattr(c_heapq, fname).__module__, '_heapq', fname)
2931

32+
def test_py_classes(self):
33+
# MinHeap and MaxHeap are only implemented in pure Python; there is no
34+
# C accelerator for them. They rely on the module-level functions,
35+
# which are the C versions when _heapq is available.
36+
for cname in class_names:
37+
self.assertEqual(getattr(py_heapq, cname).__module__, 'heapq')
38+
if c_heapq is not None:
39+
self.assertEqual(getattr(c_heapq, cname).__module__, 'heapq')
40+
3041

3142
def load_tests(loader, tests, ignore):
3243
# The 'merge' function has examples in its docstring which we should test
@@ -697,6 +708,9 @@ def test_len_and_bool(self):
697708
self.assertEqual(len(h), 1)
698709
self.assertTrue(h)
699710

711+
def test_construct_non_iterable_raises(self):
712+
self.assertRaises(TypeError, self.cls, 10)
713+
700714
def test_pop_empty_raises(self):
701715
h = self.cls()
702716
self.assertRaises(IndexError, h.pop)

0 commit comments

Comments
 (0)