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

Delta Between Two Patch Sets: Lib/test/test_bisect.py

Issue 16897: Fix test discovery for test_bisect.py
Left Patch Set: Created 6 years, 8 months ago
Right Patch Set: Created 6 years, 8 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import sys 1 import sys
2 import unittest 2 import unittest
3 from test import support 3 from test import support
4 from collections import UserList 4 from collections import UserList
5 5
6 py_bisect = support.import_fresh_module('bisect', blocked=['_bisect']) 6 py_bisect = support.import_fresh_module('bisect', blocked=['_bisect'])
7 c_bisect = support.import_fresh_module('bisect', fresh=['_bisect']) 7 c_bisect = support.import_fresh_module('bisect', fresh=['_bisect'])
8 8
9 class Range(object): 9 class Range(object):
10 """A trivial range()-like object without any integer width limitations.""" 10 """A trivial range()-like object without any integer width limitations."""
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 self.assertEqual([5, 10], lst.data) 235 self.assertEqual([5, 10], lst.data)
236 236
237 class TestInsortPython(TestInsort, unittest.TestCase): 237 class TestInsortPython(TestInsort, unittest.TestCase):
238 module = py_bisect 238 module = py_bisect
239 239
240 class TestInsortC(TestInsort, unittest.TestCase): 240 class TestInsortC(TestInsort, unittest.TestCase):
241 module = c_bisect 241 module = c_bisect
242 242
243 #============================================================================== 243 #==============================================================================
244 244
245
246 class LenOnly: 245 class LenOnly:
247 "Dummy sequence class defining __len__ but not __getitem__." 246 "Dummy sequence class defining __len__ but not __getitem__."
248 def __len__(self): 247 def __len__(self):
249 return 10 248 return 10
250 249
251 class GetOnly: 250 class GetOnly:
252 "Dummy sequence class defining __getitem__ but not __len__." 251 "Dummy sequence class defining __getitem__ but not __len__."
253 def __getitem__(self, ndx): 252 def __getitem__(self, ndx):
254 return 10 253 return 10
255 254
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 self.assertRaises(TypeError, f, 10) 290 self.assertRaises(TypeError, f, 10)
292 291
293 class TestErrorHandlingPython(TestErrorHandling, unittest.TestCase): 292 class TestErrorHandlingPython(TestErrorHandling, unittest.TestCase):
294 module = py_bisect 293 module = py_bisect
295 294
296 class TestErrorHandlingC(TestErrorHandling, unittest.TestCase): 295 class TestErrorHandlingC(TestErrorHandling, unittest.TestCase):
297 module = c_bisect 296 module = c_bisect
298 297
299 #============================================================================== 298 #==============================================================================
300 299
301 libreftest = """ 300 class TestDocExample:
302 Example from the Library Reference: Doc/library/bisect.rst 301 def test_grades(self):
303 302 def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
304 The bisect() function is generally useful for categorizing numeric data. 303 i = self.module.bisect(breakpoints, score)
305 This example uses bisect() to look up a letter grade for an exam total 304 return grades[i]
306 (say) based on a set of ordered numeric breakpoints: 85 and up is an `A', 305
307 75..84 is a `B', etc. 306 result = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
308 307 self.assertEqual(result, ['F', 'A', 'C', 'C', 'B', 'A', 'A'])
309 >>> grades = "FEDCBA" 308
310 >>> breakpoints = [30, 44, 66, 75, 85] 309 class TestDocExamplePython(TestDocExample, unittest.TestCase):
311 >>> from bisect import bisect 310 module = py_bisect
312 >>> def grade(total): 311
313 ... return grades[bisect(breakpoints, total)] 312 class TestDocExampleC(TestDocExample, unittest.TestCase):
314 ... 313 module = c_bisect
315 >>> grade(66)
316 'C'
317 >>> list(map(grade, [33, 99, 77, 44, 12, 88]))
318 ['E', 'A', 'B', 'D', 'F', 'A']
319
320 """
321 314
322 #------------------------------------------------------------------------------ 315 #------------------------------------------------------------------------------
323 316
324 __test__ = {'libreftest' : libreftest}
325
326 def test_main(verbose=None):
327 from test import test_bisect
328
329 test_classes = [TestBisectPython, TestBisectC,
330 TestInsortPython, TestInsortC,
331 TestErrorHandlingPython, TestErrorHandlingC]
332
333 support.run_unittest(*test_classes)
334 support.run_doctest(test_bisect, verbose)
335
336 # verify reference counting
337 if verbose and hasattr(sys, "gettotalrefcount"):
338 import gc
339 counts = [None] * 5
340 for i in range(len(counts)):
341 support.run_unittest(*test_classes)
342 gc.collect()
343 counts[i] = sys.gettotalrefcount()
344 print(counts)
345
346 if __name__ == "__main__": 317 if __name__ == "__main__":
347 test_main(verbose=True) 318 unittest.main()
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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