summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_range.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-08 19:01:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-08 19:01:18 (GMT)
commitdf53392f0d7977e0439fb43684af5a805d5e4a45 (patch)
treeb7abbdca481a81b9fd02b7329c3d30c1558942ba /Lib/test/test_range.py
parentaa078674e01090b000f7af89734a4d8b64a4422d (diff)
downloadcpython-df53392f0d7977e0439fb43684af5a805d5e4a45.zip
cpython-df53392f0d7977e0439fb43684af5a805d5e4a45.tar.gz
cpython-df53392f0d7977e0439fb43684af5a805d5e4a45.tar.bz2
Issue #28376: Creating instances of range_iterator by calling range_iterator
type now is disallowed. Calling iter() on range instance is the only way. Patch by Oren Milman.
Diffstat (limited to 'Lib/test/test_range.py')
-rw-r--r--Lib/test/test_range.py37
1 files changed, 6 insertions, 31 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py
index 9e11e51..3675f25 100644
--- a/Lib/test/test_range.py
+++ b/Lib/test/test_range.py
@@ -4,7 +4,6 @@ import unittest
import sys
import pickle
import itertools
-import test.support
# pure Python implementations (3 args only), for comparison
def pyrange(start, stop, step):
@@ -494,37 +493,13 @@ class RangeTest(unittest.TestCase):
test_id = "reversed(range({}, {}, {}))".format(start, end, step)
self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
- @test.support.cpython_only
- def test_range_iterator_invocation(self):
- import _testcapi
+ def test_range_iterators_invocation(self):
+ # verify range iterators instances cannot be created by
+ # calling their type
rangeiter_type = type(iter(range(0)))
-
- self.assertWarns(DeprecationWarning, rangeiter_type, 1, 3, 1)
-
- with test.support.check_warnings(('', DeprecationWarning)):
- # rangeiter_new doesn't take keyword arguments
- with self.assertRaises(TypeError):
- rangeiter_type(a=1)
-
- # rangeiter_new takes exactly 3 arguments
- self.assertRaises(TypeError, rangeiter_type)
- self.assertRaises(TypeError, rangeiter_type, 1)
- self.assertRaises(TypeError, rangeiter_type, 1, 1)
- self.assertRaises(TypeError, rangeiter_type, 1, 1, 1, 1)
-
- # start, stop and stop must fit in C long
- for good_val in [_testcapi.LONG_MAX, _testcapi.LONG_MIN]:
- rangeiter_type(good_val, good_val, good_val)
- for bad_val in [_testcapi.LONG_MAX + 1, _testcapi.LONG_MIN - 1]:
- self.assertRaises(OverflowError,
- rangeiter_type, bad_val, 1, 1)
- self.assertRaises(OverflowError,
- rangeiter_type, 1, bad_val, 1)
- self.assertRaises(OverflowError,
- rangeiter_type, 1, 1, bad_val)
-
- # step mustn't be zero
- self.assertRaises(ValueError, rangeiter_type, 1, 1, 0)
+ self.assertRaises(TypeError, rangeiter_type, 1, 3, 1)
+ long_rangeiter_type = type(iter(range(1 << 1000)))
+ self.assertRaises(TypeError, long_rangeiter_type, 1, 3, 1)
def test_slice(self):
def check(start, stop, step=None):