diff options
Diffstat (limited to 'Lib/test/test_bisect.py')
-rw-r--r-- | Lib/test/test_bisect.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py index 5c3330b4e41..f95ed635c3b 100644 --- a/Lib/test/test_bisect.py +++ b/Lib/test/test_bisect.py @@ -1,7 +1,7 @@ import sys import unittest -from test import test_support -from UserList import UserList +from test import support +from collections import UserList # We do a bit of trickery here to be able to test both the C implementation # and the Python implementation of the module. @@ -24,7 +24,7 @@ import bisect as c_bisect class Range(object): - """A trivial xrange()-like object without any integer width limitations.""" + """A trivial range()-like object without any integer width limitations.""" def __init__(self, start, stop): self.start = start self.stop = stop @@ -148,10 +148,7 @@ class TestBisect(unittest.TestCase): # Issue 13496 mod = self.module n = sys.maxsize - try: - data = xrange(n-1) - except OverflowError: - self.skipTest("can't create a xrange() object of size `sys.maxsize`") + data = range(n-1) self.assertEqual(mod.bisect_left(data, n-3), n-3) self.assertEqual(mod.bisect_right(data, n-3), n-2) self.assertEqual(mod.bisect_left(data, n-3, n-10, n), n-3) @@ -175,8 +172,8 @@ class TestBisect(unittest.TestCase): def test_random(self, n=25): from random import randrange - for i in xrange(n): - data = [randrange(0, n, 2) for j in xrange(i)] + for i in range(n): + data = [randrange(0, n, 2) for j in range(i)] data.sort() elem = randrange(-1, n+1) ip = self.module.bisect_left(data, elem) @@ -192,9 +189,9 @@ class TestBisect(unittest.TestCase): def test_optionalSlicing(self): for func, data, elem, expected in self.precomputedCases: - for lo in xrange(4): + for lo in range(4): lo = min(len(data), lo) - for hi in xrange(3,8): + for hi in range(3,8): hi = min(len(data), hi) ip = func(data, elem, lo, hi) self.assertTrue(lo <= ip <= hi) @@ -235,7 +232,7 @@ class TestInsort(unittest.TestCase): def test_vsBuiltinSort(self, n=500): from random import choice for insorted in (list(), UserList()): - for i in xrange(n): + for i in range(n): digit = choice("0123456789") if digit in "02468": f = self.module.insort_left @@ -279,8 +276,13 @@ class GetOnly: class CmpErr: "Dummy element that always raises an error during comparison" - def __cmp__(self, other): + def __lt__(self, other): raise ZeroDivisionError + __gt__ = __lt__ + __le__ = __lt__ + __ge__ = __lt__ + __eq__ = __lt__ + __ne__ = __lt__ class TestErrorHandling(unittest.TestCase): module = None @@ -293,12 +295,12 @@ class TestErrorHandling(unittest.TestCase): def test_len_only(self): for f in (self.module.bisect_left, self.module.bisect_right, self.module.insort_left, self.module.insort_right): - self.assertRaises(AttributeError, f, LenOnly(), 10) + self.assertRaises(TypeError, f, LenOnly(), 10) def test_get_only(self): for f in (self.module.bisect_left, self.module.bisect_right, self.module.insort_left, self.module.insort_right): - self.assertRaises(AttributeError, f, GetOnly(), 10) + self.assertRaises(TypeError, f, GetOnly(), 10) def test_cmp_err(self): seq = [CmpErr(), CmpErr(), CmpErr()] @@ -335,7 +337,7 @@ This example uses bisect() to look up a letter grade for an exam total ... >>> grade(66) 'C' - >>> map(grade, [33, 99, 77, 44, 12, 88]) + >>> list(map(grade, [33, 99, 77, 44, 12, 88])) ['E', 'A', 'B', 'D', 'F', 'A'] """ @@ -351,18 +353,18 @@ def test_main(verbose=None): TestInsortPython, TestInsortC, TestErrorHandlingPython, TestErrorHandlingC] - test_support.run_unittest(*test_classes) - test_support.run_doctest(test_bisect, verbose) + support.run_unittest(*test_classes) + support.run_doctest(test_bisect, verbose) # verify reference counting if verbose and hasattr(sys, "gettotalrefcount"): import gc counts = [None] * 5 - for i in xrange(len(counts)): - test_support.run_unittest(*test_classes) + for i in range(len(counts)): + support.run_unittest(*test_classes) gc.collect() counts[i] = sys.gettotalrefcount() - print counts + print(counts) if __name__ == "__main__": test_main(verbose=True) |