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

Side by Side Diff: Lib/test/test_range.py

Issue 28376: assertion failure in rangeobject.c
Patch Set: Created 3 years, 6 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « no previous file | Objects/rangeobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Python test set -- built-in functions 1 # Python test set -- built-in functions
2 2
3 import test.support, unittest 3 import test.support, unittest
4 import sys 4 import sys
5 import pickle 5 import pickle
6 import itertools 6 import itertools
7 7
8 # pure Python implementations (3 args only), for comparison 8 # pure Python implementations (3 args only), for comparison
9 def pyrange(start, stop, step): 9 def pyrange(start, stop, step):
10 if (start - stop) // step < 0: 10 if (start - stop) // step < 0:
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 iter1 = range(start, end, step) 485 iter1 = range(start, end, step)
486 iter2 = pyrange(start, end, step) 486 iter2 = pyrange(start, end, step)
487 test_id = "range({}, {}, {})".format(start, end, step) 487 test_id = "range({}, {}, {})".format(start, end, step)
488 # check first 100 entries 488 # check first 100 entries
489 self.assert_iterators_equal(iter1, iter2, test_id, limit=100) 489 self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
490 490
491 iter1 = reversed(range(start, end, step)) 491 iter1 = reversed(range(start, end, step))
492 iter2 = pyrange_reversed(start, end, step) 492 iter2 = pyrange_reversed(start, end, step)
493 test_id = "reversed(range({}, {}, {}))".format(start, end, step) 493 test_id = "reversed(range({}, {}, {}))".format(start, end, step)
494 self.assert_iterators_equal(iter1, iter2, test_id, limit=100) 494 self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
495
496 @test.support.cpython_only
497 def test_range_iterator_invocation(self):
498 import _testcapi
499 rangeiter_type = type(iter(range(0)))
500
501 # rangeiter_new doesn't take keyword arguments
502 with self.assertRaises(TypeError):
503 rangeiter_type(a=1)
504
505 # rangeiter_new takes exactly 3 arguments
506 self.assertRaises(TypeError, rangeiter_type)
507 self.assertRaises(TypeError, rangeiter_type, 1)
508 self.assertRaises(TypeError, rangeiter_type, 1, 1)
509 self.assertRaises(TypeError, rangeiter_type, 1, 1, 1, 1)
510
511 # start, stop and stop must fit in C long
512 for good_val in [_testcapi.LONG_MAX, _testcapi.LONG_MIN]:
513 rangeiter_type(good_val, good_val, good_val)
514 for bad_val in [_testcapi.LONG_MAX + 1, _testcapi.LONG_MIN - 1]:
515 self.assertRaises(OverflowError,
516 rangeiter_type, bad_val, 1, 1)
517 self.assertRaises(OverflowError,
518 rangeiter_type, 1, bad_val, 1)
519 self.assertRaises(OverflowError,
520 rangeiter_type, 1, 1, bad_val)
521
522 # step mustn't be zero
523 self.assertRaises(ValueError, rangeiter_type, 1, 1, 0)
495 524
496 def test_slice(self): 525 def test_slice(self):
497 def check(start, stop, step=None): 526 def check(start, stop, step=None):
498 i = slice(start, stop, step) 527 i = slice(start, stop, step)
499 self.assertEqual(list(r[i]), list(r)[i]) 528 self.assertEqual(list(r[i]), list(r)[i])
500 self.assertEqual(len(r[i]), len(list(r)[i])) 529 self.assertEqual(len(r[i]), len(list(r)[i]))
501 for r in [range(10), 530 for r in [range(10),
502 range(0), 531 range(0),
503 range(1, 9, 3), 532 range(1, 9, 3),
504 range(8, 0, -3), 533 range(8, 0, -3),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 671
643 with self.assertRaises(AttributeError): 672 with self.assertRaises(AttributeError):
644 del rangeobj.start 673 del rangeobj.start
645 with self.assertRaises(AttributeError): 674 with self.assertRaises(AttributeError):
646 del rangeobj.stop 675 del rangeobj.stop
647 with self.assertRaises(AttributeError): 676 with self.assertRaises(AttributeError):
648 del rangeobj.step 677 del rangeobj.step
649 678
650 if __name__ == "__main__": 679 if __name__ == "__main__":
651 unittest.main() 680 unittest.main()
OLDNEW
« 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+