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

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 unittest 3 import 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 def test_range_iterator_invocation(self):
storchaka 2016/10/06 18:59:22 Seems the ability to call range iterator construct
497 import _testcapi
498 rangeiter_type = type(iter(range(0)))
499
500 # rangeiter_new doesn't take keyword arguments
501 with self.assertRaises(TypeError):
502 rangeiter_type(a=1)
503
504 # rangeiter_new takes exactly 3 arguments
505 self.assertRaises(TypeError, rangeiter_type)
506 self.assertRaises(TypeError, rangeiter_type, 1)
507 self.assertRaises(TypeError, rangeiter_type, 1, 1)
508 self.assertRaises(TypeError, rangeiter_type, 1, 1, 1, 1)
509
510 # start, stop and stop must fit in C long
511 for good_val in [_testcapi.LONG_MAX, _testcapi.LONG_MIN]:
512 rangeiter_type(good_val, good_val, good_val)
513 for bad_val in [_testcapi.LONG_MAX + 1, _testcapi.LONG_MIN - 1]:
514 self.assertRaises(OverflowError,
515 rangeiter_type, bad_val, 1, 1)
516 self.assertRaises(OverflowError,
517 rangeiter_type, 1, bad_val, 1)
518 self.assertRaises(OverflowError,
519 rangeiter_type, 1, 1, bad_val)
520
521 # step mustn't be zero
522 self.assertRaises(ValueError, rangeiter_type, 1, 1, 0)
495 523
496 def test_slice(self): 524 def test_slice(self):
497 def check(start, stop, step=None): 525 def check(start, stop, step=None):
498 i = slice(start, stop, step) 526 i = slice(start, stop, step)
499 self.assertEqual(list(r[i]), list(r)[i]) 527 self.assertEqual(list(r[i]), list(r)[i])
500 self.assertEqual(len(r[i]), len(list(r)[i])) 528 self.assertEqual(len(r[i]), len(list(r)[i]))
501 for r in [range(10), 529 for r in [range(10),
502 range(0), 530 range(0),
503 range(1, 9, 3), 531 range(1, 9, 3),
504 range(8, 0, -3), 532 range(8, 0, -3),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 670
643 with self.assertRaises(AttributeError): 671 with self.assertRaises(AttributeError):
644 del rangeobj.start 672 del rangeobj.start
645 with self.assertRaises(AttributeError): 673 with self.assertRaises(AttributeError):
646 del rangeobj.stop 674 del rangeobj.stop
647 with self.assertRaises(AttributeError): 675 with self.assertRaises(AttributeError):
648 del rangeobj.step 676 del rangeobj.step
649 677
650 if __name__ == "__main__": 678 if __name__ == "__main__":
651 unittest.main() 679 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+