summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-08 18:43:11 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-08 18:43:11 (GMT)
commit44759bcf13d6b47323fd4c6e4d62b7146ed0a5b1 (patch)
tree3d081321de9426abac60ce6fff6f8a355a171176 /Lib
parent3bd9fde4dfa2e8c50ea10c48a819b1dddafb6dc4 (diff)
downloadcpython-44759bcf13d6b47323fd4c6e4d62b7146ed0a5b1.zip
cpython-44759bcf13d6b47323fd4c6e4d62b7146ed0a5b1.tar.gz
cpython-44759bcf13d6b47323fd4c6e4d62b7146ed0a5b1.tar.bz2
Issue #28376: The constructor of range_iterator now checks that step is not 0.
Patch by Oren Milman.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_range.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py
index 106c732..c022f07 100644
--- a/Lib/test/test_range.py
+++ b/Lib/test/test_range.py
@@ -493,6 +493,35 @@ 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
+ rangeiter_type = type(iter(range(0)))
+
+ # 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)
+
def test_slice(self):
def check(start, stop, step=None):
i = slice(start, stop, step)