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

Delta Between Two Patch Sets: Lib/test/test_operator.py

Issue 602: range: lean and mean (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/branches/py3k/
Left Patch Set: address more concerns Created 4 months, 1 week ago , Downloaded from: http://bugs.python.org/file10183/range_lean_and_mean5.patch
Right Patch Set: __len__ is back! Created 4 months, 1 week ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 import operator 1 import operator
2 import unittest 2 import unittest
3 3
4 from test import test_support 4 from test import test_support
5 5
6 class Seq1: 6 class Seq1:
7 def __init__(self, lst): 7 def __init__(self, lst):
8 self.lst = lst 8 self.lst = lst
9 def __len__(self): 9 def __len__(self):
10 return len(self.lst) 10 return len(self.lst)
11 def __getitem__(self, i): 11 def __getitem__(self, i):
12 return self.lst[i] 12 return self.lst[i]
13 def __add__(self, other): 13 def __add__(self, other):
14 return self.lst + other.lst 14 return self.lst + other.lst
15 def __mul__(self, other): 15 def __mul__(self, other):
16 return self.lst * other 16 return self.lst * other
17 def __rmul__(self, other): 17 def __rmul__(self, other):
18 return other * self.lst 18 return other * self.lst
19 19
20 class Seq2(object): 20 class Seq2(object):
21 def __init__(self, lst): 21 def __init__(self, lst):
22 self.lst = lst 22 self.lst = lst
23 def __len__(self): 23 def __len__(self):
24 return len(self.lst) 24 return len(self.lst)
25 def __getitem__(self, i): 25 def __getitem__(self, i):
26 return self.lst[i] 26 return self.lst[i]
27 def __add__(self, other): 27 def __add__(self, other):
28 return self.lst + other.lst 28 return self.lst + other.lst
29 def __mul__(self, other): 29 def __mul__(self, other):
30 return self.lst * other 30 return self.lst * other
31 def __rmul__(self, other): 31 def __rmul__(self, other):
32 return other * self.lst 32 return other * self.lst
33 33
34 34
35 class OperatorTestCase(unittest.TestCase): 35 class OperatorTestCase(unittest.TestCase):
36 def test_lt(self): 36 def test_lt(self):
37 self.failUnlessRaises(TypeError, operator.lt) 37 self.failUnlessRaises(TypeError, operator.lt)
38 self.failUnlessRaises(TypeError, operator.lt, 1j, 2j) 38 self.failUnlessRaises(TypeError, operator.lt, 1j, 2j)
39 self.failIf(operator.lt(1, 0)) 39 self.failIf(operator.lt(1, 0))
40 self.failIf(operator.lt(1, 0.0)) 40 self.failIf(operator.lt(1, 0.0))
41 self.failIf(operator.lt(1, 1)) 41 self.failIf(operator.lt(1, 1))
42 self.failIf(operator.lt(1, 1.0)) 42 self.failIf(operator.lt(1, 1.0))
43 self.failUnless(operator.lt(1, 2)) 43 self.failUnless(operator.lt(1, 2))
44 self.failUnless(operator.lt(1, 2.0)) 44 self.failUnless(operator.lt(1, 2.0))
45 45
46 def test_le(self): 46 def test_le(self):
47 self.failUnlessRaises(TypeError, operator.le) 47 self.failUnlessRaises(TypeError, operator.le)
48 self.failUnlessRaises(TypeError, operator.le, 1j, 2j) 48 self.failUnlessRaises(TypeError, operator.le, 1j, 2j)
49 self.failIf(operator.le(1, 0)) 49 self.failIf(operator.le(1, 0))
50 self.failIf(operator.le(1, 0.0)) 50 self.failIf(operator.le(1, 0.0))
(...skipping 381 matching lines...) Show 10 above Show 10 below
432 c = C() 432 c = C()
433 self.assertEqual(operator.iadd (c, 5), "iadd") 433 self.assertEqual(operator.iadd (c, 5), "iadd")
434 self.assertEqual(operator.iand (c, 5), "iand") 434 self.assertEqual(operator.iand (c, 5), "iand")
435 self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv") 435 self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
436 self.assertEqual(operator.ilshift (c, 5), "ilshift") 436 self.assertEqual(operator.ilshift (c, 5), "ilshift")
437 self.assertEqual(operator.imod (c, 5), "imod") 437 self.assertEqual(operator.imod (c, 5), "imod")
438 self.assertEqual(operator.imul (c, 5), "imul") 438 self.assertEqual(operator.imul (c, 5), "imul")
439 self.assertEqual(operator.ior (c, 5), "ior") 439 self.assertEqual(operator.ior (c, 5), "ior")
440 self.assertEqual(operator.ipow (c, 5), "ipow") 440 self.assertEqual(operator.ipow (c, 5), "ipow")
441 self.assertEqual(operator.irshift (c, 5), "irshift") 441 self.assertEqual(operator.irshift (c, 5), "irshift")
442 self.assertEqual(operator.isub (c, 5), "isub") 442 self.assertEqual(operator.isub (c, 5), "isub")
443 self.assertEqual(operator.itruediv (c, 5), "itruediv") 443 self.assertEqual(operator.itruediv (c, 5), "itruediv")
444 self.assertEqual(operator.ixor (c, 5), "ixor") 444 self.assertEqual(operator.ixor (c, 5), "ixor")
445 self.assertEqual(operator.iconcat (c, c), "iadd") 445 self.assertEqual(operator.iconcat (c, c), "iadd")
446 self.assertEqual(operator.irepeat (c, 5), "imul") 446 self.assertEqual(operator.irepeat (c, 5), "imul")
447 self.assertEqual(operator.__iadd__ (c, 5), "iadd") 447 self.assertEqual(operator.__iadd__ (c, 5), "iadd")
448 self.assertEqual(operator.__iand__ (c, 5), "iand") 448 self.assertEqual(operator.__iand__ (c, 5), "iand")
449 self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv") 449 self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv")
450 self.assertEqual(operator.__ilshift__ (c, 5), "ilshift") 450 self.assertEqual(operator.__ilshift__ (c, 5), "ilshift")
451 self.assertEqual(operator.__imod__ (c, 5), "imod") 451 self.assertEqual(operator.__imod__ (c, 5), "imod")
452 self.assertEqual(operator.__imul__ (c, 5), "imul") 452 self.assertEqual(operator.__imul__ (c, 5), "imul")
453 self.assertEqual(operator.__ior__ (c, 5), "ior") 453 self.assertEqual(operator.__ior__ (c, 5), "ior")
454 self.assertEqual(operator.__ipow__ (c, 5), "ipow") 454 self.assertEqual(operator.__ipow__ (c, 5), "ipow")
455 self.assertEqual(operator.__irshift__ (c, 5), "irshift") 455 self.assertEqual(operator.__irshift__ (c, 5), "irshift")
456 self.assertEqual(operator.__isub__ (c, 5), "isub") 456 self.assertEqual(operator.__isub__ (c, 5), "isub")
457 self.assertEqual(operator.__itruediv__ (c, 5), "itruediv") 457 self.assertEqual(operator.__itruediv__ (c, 5), "itruediv")
458 self.assertEqual(operator.__ixor__ (c, 5), "ixor") 458 self.assertEqual(operator.__ixor__ (c, 5), "ixor")
459 self.assertEqual(operator.__iconcat__ (c, c), "iadd") 459 self.assertEqual(operator.__iconcat__ (c, c), "iadd")
460 self.assertEqual(operator.__irepeat__ (c, 5), "imul") 460 self.assertEqual(operator.__irepeat__ (c, 5), "imul")
461 461
462 def test_main(verbose=None): 462 def test_main(verbose=None):
463 import sys 463 import sys
464 test_classes = ( 464 test_classes = (
465 OperatorTestCase, 465 OperatorTestCase,
466 ) 466 )
467 467
468 test_support.run_unittest(*test_classes) 468 test_support.run_unittest(*test_classes)
469 469
470 # verify reference counting 470 # verify reference counting
471 if verbose and hasattr(sys, "gettotalrefcount"): 471 if verbose and hasattr(sys, "gettotalrefcount"):
472 import gc 472 import gc
473 counts = [None] * 5 473 counts = [None] * 5
474 for i in range(len(counts)): 474 for i in range(len(counts)):
475 test_support.run_unittest(*test_classes) 475 test_support.run_unittest(*test_classes)
476 gc.collect() 476 gc.collect()
477 counts[i] = sys.gettotalrefcount() 477 counts[i] = sys.gettotalrefcount()
478 print(counts) 478 print(counts)
479 479
480 if __name__ == "__main__": 480 if __name__ == "__main__":
481 test_main(verbose=True) 481 test_main(verbose=True)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld r305