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

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

Issue 25958: Implicit ABCs have no means of "anti-registration"
Patch Set: Created 4 years, 1 month 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 import unittest 1 import unittest
2 import operator 2 import operator
3 import sys 3 import sys
4 import pickle 4 import pickle
5 5
6 from test import support 6 from test import support
7 7
8 class G: 8 class G:
9 'Sequence using __getitem__' 9 'Sequence using __getitem__'
10 def __init__(self, seqn): 10 def __init__(self, seqn):
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 # Objects must have __len__() and __getitem__() implemented. 224 # Objects must have __len__() and __getitem__() implemented.
225 class NoLen(object): 225 class NoLen(object):
226 def __getitem__(self): return 1 226 def __getitem__(self): return 1
227 nl = NoLen() 227 nl = NoLen()
228 self.assertRaises(TypeError, reversed, nl) 228 self.assertRaises(TypeError, reversed, nl)
229 229
230 class NoGetItem(object): 230 class NoGetItem(object):
231 def __len__(self): return 2 231 def __len__(self): return 2
232 ngi = NoGetItem() 232 ngi = NoGetItem()
233 self.assertRaises(TypeError, reversed, ngi) 233 self.assertRaises(TypeError, reversed, ngi)
234
235 class Blocked(object):
236 def __getitem__(self): return 1
Martin Panter 2016/01/09 02:34:57 Please fix or remove the signature. You can also f
abarnert 2016/01/18 20:28:42 Well, removing it would defeat the entire purpose
237 def __len__(self): return 2
238 __reversed__ = None
239 b = Blocked()
240 self.assertRaises(TypeError, reversed, b)
234 241
235 def test_pickle(self): 242 def test_pickle(self):
236 for data in 'abc', range(5), tuple(enumerate('abc')), range(1,17,5): 243 for data in 'abc', range(5), tuple(enumerate('abc')), range(1,17,5):
237 self.check_pickle(reversed(data), list(data)[::-1]) 244 self.check_pickle(reversed(data), list(data)[::-1])
238 245
239 246
240 class EnumerateStartTestCase(EnumerateTestCase): 247 class EnumerateStartTestCase(EnumerateTestCase):
241 248
242 def test_basicfunction(self): 249 def test_basicfunction(self):
243 e = self.enum(self.seq) 250 e = self.enum(self.seq)
244 self.assertEqual(iter(e), e) 251 self.assertEqual(iter(e), e)
245 self.assertEqual(list(self.enum(self.seq)), self.res) 252 self.assertEqual(list(self.enum(self.seq)), self.res)
246 253
247 254
248 class TestStart(EnumerateStartTestCase): 255 class TestStart(EnumerateStartTestCase):
249 256
250 enum = lambda self, i: enumerate(i, start=11) 257 enum = lambda self, i: enumerate(i, start=11)
251 seq, res = 'abc', [(11, 'a'), (12, 'b'), (13, 'c')] 258 seq, res = 'abc', [(11, 'a'), (12, 'b'), (13, 'c')]
252 259
253 260
254 class TestLongStart(EnumerateStartTestCase): 261 class TestLongStart(EnumerateStartTestCase):
255 262
256 enum = lambda self, i: enumerate(i, start=sys.maxsize+1) 263 enum = lambda self, i: enumerate(i, start=sys.maxsize+1)
257 seq, res = 'abc', [(sys.maxsize+1,'a'), (sys.maxsize+2,'b'), 264 seq, res = 'abc', [(sys.maxsize+1,'a'), (sys.maxsize+2,'b'),
258 (sys.maxsize+3,'c')] 265 (sys.maxsize+3,'c')]
259 266
260 267
261 if __name__ == "__main__": 268 if __name__ == "__main__":
262 unittest.main() 269 unittest.main()
OLDNEW

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