diff options
Diffstat (limited to 'Lib/test/test_range.py')
-rw-r--r-- | Lib/test/test_range.py | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index aab98ab..2dbcebc 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -313,7 +313,7 @@ class RangeTest(unittest.TestCase): self.assertRaises(TypeError, range, IN()) # Test use of user-defined classes in slice indices. - self.assertEqual(list(range(10)[:I(5)]), list(range(5))) + self.assertEqual(range(10)[:I(5)], range(5)) with self.assertRaises(RuntimeError): range(0, 10)[:IX()] @@ -353,9 +353,10 @@ class RangeTest(unittest.TestCase): (13, 21, 3), (-2, 2, 2), (2**65, 2**65+2)] for proto in range(pickle.HIGHEST_PROTOCOL + 1): for t in testcases: - r = range(*t) - self.assertEqual(list(pickle.loads(pickle.dumps(r, proto))), - list(r)) + with self.subTest(proto=proto, test=t): + r = range(*t) + self.assertEqual(list(pickle.loads(pickle.dumps(r, proto))), + list(r)) def test_iterator_pickling(self): testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1), @@ -365,7 +366,7 @@ class RangeTest(unittest.TestCase): it = itorg = iter(range(*t)) data = list(range(*t)) - d = pickle.dumps(it) + d = pickle.dumps(it, proto) it = pickle.loads(d) self.assertEqual(type(itorg), type(it)) self.assertEqual(list(it), data) @@ -375,33 +376,35 @@ class RangeTest(unittest.TestCase): next(it) except StopIteration: continue - d = pickle.dumps(it) + d = pickle.dumps(it, proto) it = pickle.loads(d) self.assertEqual(list(it), data[1:]) def test_exhausted_iterator_pickling(self): - r = range(2**65, 2**65+2) - i = iter(r) - while True: - r = next(i) - if r == 2**65+1: - break - d = pickle.dumps(i) - i2 = pickle.loads(d) - self.assertEqual(list(i), []) - self.assertEqual(list(i2), []) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + r = range(2**65, 2**65+2) + i = iter(r) + while True: + r = next(i) + if r == 2**65+1: + break + d = pickle.dumps(i, proto) + i2 = pickle.loads(d) + self.assertEqual(list(i), []) + self.assertEqual(list(i2), []) def test_large_exhausted_iterator_pickling(self): - r = range(20) - i = iter(r) - while True: - r = next(i) - if r == 19: - break - d = pickle.dumps(i) - i2 = pickle.loads(d) - self.assertEqual(list(i), []) - self.assertEqual(list(i2), []) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + r = range(20) + i = iter(r) + while True: + r = next(i) + if r == 19: + break + d = pickle.dumps(i, proto) + i2 = pickle.loads(d) + self.assertEqual(list(i), []) + self.assertEqual(list(i2), []) def test_odd_bug(self): # This used to raise a "SystemError: NULL result without error" |