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

## Delta Between Two Patch Sets: Lib/test/test_range.py

Issue 28376: assertion failure in rangeobject.c
Left Patch Set: Created 3 years, 8 months ago
Right Patch Set: Created 3 years, 7 months ago
 Left: Base Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Patch Set 6: None Patch Set 7: None Right: Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Patch Set 6: None Patch Set 7: None
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Objects/rangeobject.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Hide Comments ('s')
LEFTRIGHT
1 # Python test set -- built-in functions 1 # Python test set -- built-in functions
2 2
3 import unittest 3 import unittest
4 import sys 4 import sys
5 import pickle 5 import pickle
6 import itertools 6 import itertools
7 import test.support
7 8
8 # pure Python implementations (3 args only), for comparison 9 # pure Python implementations (3 args only), for comparison
9 def pyrange(start, stop, step): 10 def pyrange(start, stop, step):
10 if (start - stop) // step < 0: 11 if (start - stop) // step < 0:
11 # replace stop with next element in the sequence of integers 12 # replace stop with next element in the sequence of integers
12 # that are congruent to start modulo step. 13 # that are congruent to start modulo step.
13 stop += (start - stop) % step 14 stop += (start - stop) % step
14 while start != stop: 15 while start != stop:
15 yield start 16 yield start
16 start += step 17 start += step
(...skipping 469 matching lines...)
486 iter2 = pyrange(start, end, step) 487 iter2 = pyrange(start, end, step)
487 test_id = "range({}, {}, {})".format(start, end, step) 488 test_id = "range({}, {}, {})".format(start, end, step)
488 # check first 100 entries 489 # check first 100 entries
489 self.assert_iterators_equal(iter1, iter2, test_id, limit=100) 490 self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
490 491
491 iter1 = reversed(range(start, end, step)) 492 iter1 = reversed(range(start, end, step))
492 iter2 = pyrange_reversed(start, end, step) 493 iter2 = pyrange_reversed(start, end, step)
493 test_id = "reversed(range({}, {}, {}))".format(start, end, step) 494 test_id = "reversed(range({}, {}, {}))".format(start, end, step)
494 self.assert_iterators_equal(iter1, iter2, test_id, limit=100) 495 self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
495 496
497 @test.support.cpython_only
496 def test_range_iterator_invocation(self): 498 def test_range_iterator_invocation(self):
storchaka 2016/10/06 18:59:22 Seems the ability to call range iterator construct
497 import _testcapi 499 import _testcapi
498 rangeiter_type = type(iter(range(0))) 500 rangeiter_type = type(iter(range(0)))
499 501
500 # rangeiter_new doesn't take keyword arguments 502 self.assertWarns(DeprecationWarning, rangeiter_type, 1, 3, 1)
501 with self.assertRaises(TypeError): 503
502 rangeiter_type(a=1) 504 with test.support.check_warnings(('', DeprecationWarning)):
503 505 # rangeiter_new doesn't take keyword arguments
504 # rangeiter_new takes exactly 3 arguments 506 with self.assertRaises(TypeError):
505 self.assertRaises(TypeError, rangeiter_type) 507 rangeiter_type(a=1)
506 self.assertRaises(TypeError, rangeiter_type, 1) 508
507 self.assertRaises(TypeError, rangeiter_type, 1, 1) 509 # rangeiter_new takes exactly 3 arguments
508 self.assertRaises(TypeError, rangeiter_type, 1, 1, 1, 1) 510 self.assertRaises(TypeError, rangeiter_type)
509 511 self.assertRaises(TypeError, rangeiter_type, 1)
510 # start, stop and stop must fit in C long 512 self.assertRaises(TypeError, rangeiter_type, 1, 1)
511 for good_val in [_testcapi.LONG_MAX, _testcapi.LONG_MIN]: 513 self.assertRaises(TypeError, rangeiter_type, 1, 1, 1, 1)
512 rangeiter_type(good_val, good_val, good_val) 514
513 for bad_val in [_testcapi.LONG_MAX + 1, _testcapi.LONG_MIN - 1]: 515 # start, stop and stop must fit in C long
514 self.assertRaises(OverflowError, 516 for good_val in [_testcapi.LONG_MAX, _testcapi.LONG_MIN]:
515 rangeiter_type, bad_val, 1, 1) 517 rangeiter_type(good_val, good_val, good_val)
516 self.assertRaises(OverflowError, 518 for bad_val in [_testcapi.LONG_MAX + 1, _testcapi.LONG_MIN - 1]:
517 rangeiter_type, 1, bad_val, 1) 519 self.assertRaises(OverflowError,
518 self.assertRaises(OverflowError, 520 rangeiter_type, bad_val, 1, 1)
519 rangeiter_type, 1, 1, bad_val) 521 self.assertRaises(OverflowError,
520 522 rangeiter_type, 1, bad_val, 1)
521 # step mustn't be zero 523 self.assertRaises(OverflowError,
522 self.assertRaises(ValueError, rangeiter_type, 1, 1, 0) 524 rangeiter_type, 1, 1, bad_val)
525
526 # step mustn't be zero
527 self.assertRaises(ValueError, rangeiter_type, 1, 1, 0)
523 528
524 def test_slice(self): 529 def test_slice(self):
525 def check(start, stop, step=None): 530 def check(start, stop, step=None):
526 i = slice(start, stop, step) 531 i = slice(start, stop, step)
527 self.assertEqual(list(r[i]), list(r)[i]) 532 self.assertEqual(list(r[i]), list(r)[i])
528 self.assertEqual(len(r[i]), len(list(r)[i])) 533 self.assertEqual(len(r[i]), len(list(r)[i]))
529 for r in [range(10), 534 for r in [range(10),
530 range(0), 535 range(0),
531 range(1, 9, 3), 536 range(1, 9, 3),
532 range(8, 0, -3), 537 range(8, 0, -3),
(...skipping 137 matching lines...)
670 675
671 with self.assertRaises(AttributeError): 676 with self.assertRaises(AttributeError):
672 del rangeobj.start 677 del rangeobj.start
673 with self.assertRaises(AttributeError): 678 with self.assertRaises(AttributeError):
674 del rangeobj.stop 679 del rangeobj.stop
675 with self.assertRaises(AttributeError): 680 with self.assertRaises(AttributeError):
676 del rangeobj.step 681 del rangeobj.step
677 682
678 if __name__ == "__main__": 683 if __name__ == "__main__":
679 unittest.main() 684 unittest.main()
LEFTRIGHT

This is Rietveld 894c83f36cb7+