Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(23)

Side by Side Diff: Lib/test/test_heapq.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_gzip.py ('k') | Lib/test/test_hmac.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Unittests for heapq.""" 1 """Unittests for heapq."""
2 2
3 import sys 3 import sys
4 import random 4 import random
5 import unittest 5 import unittest
6 6
7 from test import support 7 from test import support
8 from unittest import TestCase, skipUnless 8 from unittest import TestCase, skipUnless
9 9
10 py_heapq = support.import_fresh_module('heapq', blocked=['_heapq']) 10 py_heapq = support.import_fresh_module('heapq', blocked=['_heapq'])
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 self.assertRaises(TypeError, self.module.heappush, None, None) 54 self.assertRaises(TypeError, self.module.heappush, None, None)
55 self.assertRaises(TypeError, self.module.heappop, None) 55 self.assertRaises(TypeError, self.module.heappop, None)
56 except AttributeError: 56 except AttributeError:
57 pass 57 pass
58 58
59 def check_invariant(self, heap): 59 def check_invariant(self, heap):
60 # Check the heap invariant. 60 # Check the heap invariant.
61 for pos, item in enumerate(heap): 61 for pos, item in enumerate(heap):
62 if pos: # pos 0 has no parent 62 if pos: # pos 0 has no parent
63 parentpos = (pos-1) >> 1 63 parentpos = (pos-1) >> 1
64 self.assertTrue(heap[parentpos] <= item) 64 self.assertLessEqual(heap[parentpos], item)
65 65
66 def test_heapify(self): 66 def test_heapify(self):
67 for size in range(30): 67 for size in range(30):
68 heap = [random.random() for dummy in range(size)] 68 heap = [random.random() for dummy in range(size)]
69 self.module.heapify(heap) 69 self.module.heapify(heap)
70 self.check_invariant(heap) 70 self.check_invariant(heap)
71 71
72 self.assertRaises(TypeError, self.module.heapify, None) 72 self.assertRaises(TypeError, self.module.heapify, None)
73 73
74 def test_naive_nbest(self): 74 def test_naive_nbest(self):
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 class TestErrorHandlingPython(TestErrorHandling, TestCase): 373 class TestErrorHandlingPython(TestErrorHandling, TestCase):
374 module = py_heapq 374 module = py_heapq
375 375
376 @skipUnless(c_heapq, 'requires _heapq') 376 @skipUnless(c_heapq, 'requires _heapq')
377 class TestErrorHandlingC(TestErrorHandling, TestCase): 377 class TestErrorHandlingC(TestErrorHandling, TestCase):
378 module = c_heapq 378 module = c_heapq
379 379
380 380
381 if __name__ == "__main__": 381 if __name__ == "__main__":
382 unittest.main() 382 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_gzip.py ('k') | Lib/test/test_hmac.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+