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

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

Issue 25958: Implicit ABCs have no means of "anti-registration"
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 | « Lib/test/test_enumerate.py ('k') | Lib/test/test_unicode.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Test iterators. 1 # Test iterators.
2 2
3 import sys 3 import sys
4 import unittest 4 import unittest
5 from test.support import run_unittest, TESTFN, unlink, cpython_only 5 from test.support import run_unittest, TESTFN, unlink, cpython_only
6 from test.support import check_free_after_iterating 6 from test.support import check_free_after_iterating
7 import pickle 7 import pickle
8 import collections.abc 8 import collections.abc
9 9
10 # Test result of triple loop (too big to inline) 10 # Test result of triple loop (too big to inline)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 self.n = n 46 self.n = n
47 def __getitem__(self, i): 47 def __getitem__(self, i):
48 if 0 <= i < self.n: 48 if 0 <= i < self.n:
49 return i 49 return i
50 else: 50 else:
51 raise IndexError 51 raise IndexError
52 52
53 class UnlimitedSequenceClass: 53 class UnlimitedSequenceClass:
54 def __getitem__(self, i): 54 def __getitem__(self, i):
55 return i 55 return i
56
57 class DefaultIterClass:
58 pass
59
60 class NoIterClass:
61 def __getitem__(self, i):
62 return i
63 __iter__ = None
56 64
57 # Main test suite 65 # Main test suite
58 66
59 class TestCase(unittest.TestCase): 67 class TestCase(unittest.TestCase):
60 68
61 # Helper to check that an iterator returns a given sequence 69 # Helper to check that an iterator returns a given sequence
62 def check_iterator(self, it, seq, pickle=True): 70 def check_iterator(self, it, seq, pickle=True):
63 if pickle: 71 if pickle:
64 self.check_pickle(it, seq) 72 self.check_pickle(it, seq)
65 res = [] 73 res = []
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 next(it) 995 next(it)
988 996
989 def test_iter_neg_setstate(self): 997 def test_iter_neg_setstate(self):
990 it = iter(UnlimitedSequenceClass()) 998 it = iter(UnlimitedSequenceClass())
991 it.__setstate__(-42) 999 it.__setstate__(-42)
992 self.assertEqual(next(it), 0) 1000 self.assertEqual(next(it), 0)
993 self.assertEqual(next(it), 1) 1001 self.assertEqual(next(it), 1)
994 1002
995 def test_free_after_iterating(self): 1003 def test_free_after_iterating(self):
996 check_free_after_iterating(self, iter, SequenceClass, (0,)) 1004 check_free_after_iterating(self, iter, SequenceClass, (0,))
1005
1006 def test_error_iter(self):
1007 for typ in (DefaultIterClass, NoIterClass):
1008 self.assertRaises(TypeError, iter, typ())
997 1009
998 1010
999 def test_main(): 1011 def test_main():
1000 run_unittest(TestCase) 1012 run_unittest(TestCase)
1001 1013
1002 1014
1003 if __name__ == "__main__": 1015 if __name__ == "__main__":
1004 test_main() 1016 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_enumerate.py ('k') | Lib/test/test_unicode.py » ('j') | no next file with comments »

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