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

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

Issue 28376: assertion failure in rangeobject.c
Patch Set: Created 3 years, 4 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
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 import test.support
8 import re
7 9
8 # pure Python implementations (3 args only), for comparison 10 # pure Python implementations (3 args only), for comparison
9 def pyrange(start, stop, step): 11 def pyrange(start, stop, step):
10 if (start - stop) // step < 0: 12 if (start - stop) // step < 0:
11 # replace stop with next element in the sequence of integers 13 # replace stop with next element in the sequence of integers
12 # that are congruent to start modulo step. 14 # that are congruent to start modulo step.
13 stop += (start - stop) % step 15 stop += (start - stop) % step
14 while start != stop: 16 while start != stop:
15 yield start 17 yield start
16 start += step 18 start += step
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 iter1 = range(start, end, step) 487 iter1 = range(start, end, step)
486 iter2 = pyrange(start, end, step) 488 iter2 = pyrange(start, end, step)
487 test_id = "range({}, {}, {})".format(start, end, step) 489 test_id = "range({}, {}, {})".format(start, end, step)
488 # check first 100 entries 490 # check first 100 entries
489 self.assert_iterators_equal(iter1, iter2, test_id, limit=100) 491 self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
490 492
491 iter1 = reversed(range(start, end, step)) 493 iter1 = reversed(range(start, end, step))
492 iter2 = pyrange_reversed(start, end, step) 494 iter2 = pyrange_reversed(start, end, step)
493 test_id = "reversed(range({}, {}, {}))".format(start, end, step) 495 test_id = "reversed(range({}, {}, {}))".format(start, end, step)
494 self.assert_iterators_equal(iter1, iter2, test_id, limit=100) 496 self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
497
498 @test.support.cpython_only
storchaka 2016/10/07 14:32:00 I think this decorator is not needed. Other implem
Oren Milman 2016/10/07 16:10:00 But the test checks the exact wording of the error
storchaka 2016/10/07 16:44:09 Good point. I think we should not test exact error
499 def test_range_iterators_invocation(self):
500 rangeiter_type = type(iter(range(0)))
501 long_rangeiter_type = type(iter(range(1 << 1000)))
502 for iter_type in [rangeiter_type, long_rangeiter_type]:
503 self.assertRaisesRegex(TypeError,
504 re.escape("cannot create '{}' instances"
505 "".format(iter_type.__name__)),
506 iter_type)
495 507
496 def test_slice(self): 508 def test_slice(self):
497 def check(start, stop, step=None): 509 def check(start, stop, step=None):
498 i = slice(start, stop, step) 510 i = slice(start, stop, step)
499 self.assertEqual(list(r[i]), list(r)[i]) 511 self.assertEqual(list(r[i]), list(r)[i])
500 self.assertEqual(len(r[i]), len(list(r)[i])) 512 self.assertEqual(len(r[i]), len(list(r)[i]))
501 for r in [range(10), 513 for r in [range(10),
502 range(0), 514 range(0),
503 range(1, 9, 3), 515 range(1, 9, 3),
504 range(8, 0, -3), 516 range(8, 0, -3),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 654
643 with self.assertRaises(AttributeError): 655 with self.assertRaises(AttributeError):
644 del rangeobj.start 656 del rangeobj.start
645 with self.assertRaises(AttributeError): 657 with self.assertRaises(AttributeError):
646 del rangeobj.stop 658 del rangeobj.stop
647 with self.assertRaises(AttributeError): 659 with self.assertRaises(AttributeError):
648 del rangeobj.step 660 del rangeobj.step
649 661
650 if __name__ == "__main__": 662 if __name__ == "__main__":
651 unittest.main() 663 unittest.main()
OLDNEW
« Lib/_collections_abc.py ('K') | « Lib/_collections_abc.py ('k') | Objects/rangeobject.c » ('j') | no next file with comments »

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