Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Unified Diff: Lib/test/test_range.py

Issue 28376: assertion failure in rangeobject.c
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Objects/rangeobject.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_range.py Sat Oct 08 16:15:15 2016 +0300
+++ b/Lib/test/test_range.py Sat Oct 08 20:08:29 2016 +0300
@@ -4,6 +4,7 @@
import sys
import pickle
import itertools
+import test.support
# pure Python implementations (3 args only), for comparison
def pyrange(start, stop, step):
@@ -493,6 +494,38 @@
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)))
+
+ 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)
+
def test_slice(self):
def check(start, stop, step=None):
i = slice(start, stop, step)
« no previous file with comments | « no previous file | Objects/rangeobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+