summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-20 07:13:47 (GMT)
committerGitHub <noreply@github.com>2017-03-20 07:13:47 (GMT)
commit6fad4090ec9a27f8572bb00661b9890f01fb62f7 (patch)
tree8b47e7904802704a193ced6099b7e36ed7dac4df /Lib/test
parentd1f566f6bddc67e9870eaa75ae477208b9a199be (diff)
downloadcpython-6fad4090ec9a27f8572bb00661b9890f01fb62f7.zip
cpython-6fad4090ec9a27f8572bb00661b9890f01fb62f7.tar.gz
cpython-6fad4090ec9a27f8572bb00661b9890f01fb62f7.tar.bz2
bpo-28876: bool of large range raises OverflowError (#699) (#734)
(cherry picked from commit e46fb8611867fa3b407a813f53137929b7cb4a10)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_range.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py
index 9e11e51..679759e 100644
--- a/Lib/test/test_range.py
+++ b/Lib/test/test_range.py
@@ -99,20 +99,24 @@ class RangeTest(unittest.TestCase):
x = range(10**20+10, 10**20, 3)
self.assertEqual(len(x), 0)
self.assertEqual(len(list(x)), 0)
+ self.assertFalse(x)
x = range(10**20, 10**20+10, -3)
self.assertEqual(len(x), 0)
self.assertEqual(len(list(x)), 0)
+ self.assertFalse(x)
x = range(10**20+10, 10**20, -3)
self.assertEqual(len(x), 4)
self.assertEqual(len(list(x)), 4)
+ self.assertTrue(x)
# Now test range() with longs
- self.assertEqual(list(range(-2**100)), [])
- self.assertEqual(list(range(0, -2**100)), [])
- self.assertEqual(list(range(0, 2**100, -1)), [])
- self.assertEqual(list(range(0, 2**100, -1)), [])
+ for x in [range(-2**100),
+ range(0, -2**100),
+ range(0, 2**100, -1)]:
+ self.assertEqual(list(x), [])
+ self.assertFalse(x)
a = int(10 * sys.maxsize)
b = int(100 * sys.maxsize)
@@ -153,6 +157,7 @@ class RangeTest(unittest.TestCase):
step = x[1] - x[0]
length = 1 + ((x[-1] - x[0]) // step)
return length
+
a = -sys.maxsize
b = sys.maxsize
expected_len = b - a
@@ -160,6 +165,7 @@ class RangeTest(unittest.TestCase):
self.assertIn(a, x)
self.assertNotIn(b, x)
self.assertRaises(OverflowError, len, x)
+ self.assertTrue(x)
self.assertEqual(_range_len(x), expected_len)
self.assertEqual(x[0], a)
idx = sys.maxsize+1
@@ -177,6 +183,7 @@ class RangeTest(unittest.TestCase):
self.assertIn(a, x)
self.assertNotIn(b, x)
self.assertRaises(OverflowError, len, x)
+ self.assertTrue(x)
self.assertEqual(_range_len(x), expected_len)
self.assertEqual(x[0], a)
idx = sys.maxsize+1
@@ -195,6 +202,7 @@ class RangeTest(unittest.TestCase):
self.assertIn(a, x)
self.assertNotIn(b, x)
self.assertRaises(OverflowError, len, x)
+ self.assertTrue(x)
self.assertEqual(_range_len(x), expected_len)
self.assertEqual(x[0], a)
idx = sys.maxsize+1
@@ -213,6 +221,7 @@ class RangeTest(unittest.TestCase):
self.assertIn(a, x)
self.assertNotIn(b, x)
self.assertRaises(OverflowError, len, x)
+ self.assertTrue(x)
self.assertEqual(_range_len(x), expected_len)
self.assertEqual(x[0], a)
idx = sys.maxsize+1