<s> import operator <EOL> import unittest <EOL> from test import test_support <EOL> class Seq1 : <EOL> def __init__ ( self , lst ) : <EOL> self . lst = lst <EOL> def __len__ ( self ) : <EOL> return len ( self . lst ) <EOL> def __getitem__ ( self , i ) : <EOL> return self . lst [ i ] <EOL> def __add__ ( self , other ) : <EOL> return self . lst + other . lst <EOL> def __mul__ ( self , other ) : <EOL> return self . lst * other <EOL> def __rmul__ ( self , other ) : <EOL> return other * self . lst <EOL> class Seq2 ( object ) : <EOL> def __init__ ( self , lst ) : <EOL> self . lst = lst <EOL> def __len__ ( self ) : <EOL> return len ( self . lst ) <EOL> def __getitem__ ( self , i ) : <EOL> return self . lst [ i ] <EOL> def __add__ ( self , other ) : <EOL> return self . lst + other . lst <EOL> def __mul__ ( self , other ) : <EOL> return self . lst * other <EOL> def __rmul__ ( self , other ) : <EOL> return other * self . lst <EOL> class OperatorTestCase ( unittest . TestCase ) : <EOL> def test_lt ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . lt ) <EOL> self . failUnlessRaises ( TypeError , operator . lt , <NUM_LIT> , <NUM_LIT> ) <EOL> self . failIf ( operator . lt ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failIf ( operator . lt ( <NUM_LIT:1> , <NUM_LIT:0.0> ) ) <EOL> self . failIf ( operator . lt ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . failIf ( operator . lt ( <NUM_LIT:1> , <NUM_LIT:1.0> ) ) <EOL> self . failUnless ( operator . lt ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . failUnless ( operator . lt ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> def test_le ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . le ) <EOL> self . failUnlessRaises ( TypeError , operator . le , <NUM_LIT> , <NUM_LIT> ) <EOL> self . failIf ( operator . le ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failIf ( operator . le ( <NUM_LIT:1> , <NUM_LIT:0.0> ) ) <EOL> self . failUnless ( operator . le ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . failUnless ( operator . le ( <NUM_LIT:1> , <NUM_LIT:1.0> ) ) <EOL> self . failUnless ( operator . le ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . failUnless ( operator . le ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> def test_eq ( self ) : <EOL> class C ( object ) : <EOL> def __eq__ ( self , other ) : <EOL> raise SyntaxError <EOL> self . failUnlessRaises ( TypeError , operator . eq ) <EOL> self . failUnlessRaises ( SyntaxError , operator . eq , C ( ) , C ( ) ) <EOL> self . failIf ( operator . eq ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failIf ( operator . eq ( <NUM_LIT:1> , <NUM_LIT:0.0> ) ) <EOL> self . failUnless ( operator . eq ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . failUnless ( operator . eq ( <NUM_LIT:1> , <NUM_LIT:1.0> ) ) <EOL> self . failIf ( operator . eq ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . failIf ( operator . eq ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> def test_ne ( self ) : <EOL> class C ( object ) : <EOL> def __ne__ ( self , other ) : <EOL> raise SyntaxError <EOL> self . failUnlessRaises ( TypeError , operator . ne ) <EOL> self . failUnlessRaises ( SyntaxError , operator . ne , C ( ) , C ( ) ) <EOL> self . failUnless ( operator . ne ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failUnless ( operator . ne ( <NUM_LIT:1> , <NUM_LIT:0.0> ) ) <EOL> self . failIf ( operator . ne ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . failIf ( operator . ne ( <NUM_LIT:1> , <NUM_LIT:1.0> ) ) <EOL> self . failUnless ( operator . ne ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . failUnless ( operator . ne ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> def test_ge ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . ge ) <EOL> self . failUnlessRaises ( TypeError , operator . ge , <NUM_LIT> , <NUM_LIT> ) <EOL> self . failUnless ( operator . ge ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failUnless ( operator . ge ( <NUM_LIT:1> , <NUM_LIT:0.0> ) ) <EOL> self . failUnless ( operator . ge ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . failUnless ( operator . ge ( <NUM_LIT:1> , <NUM_LIT:1.0> ) ) <EOL> self . failIf ( operator . ge ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . failIf ( operator . ge ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> def test_gt ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . gt ) <EOL> self . failUnlessRaises ( TypeError , operator . gt , <NUM_LIT> , <NUM_LIT> ) <EOL> self . failUnless ( operator . gt ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failUnless ( operator . gt ( <NUM_LIT:1> , <NUM_LIT:0.0> ) ) <EOL> self . failIf ( operator . gt ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . failIf ( operator . gt ( <NUM_LIT:1> , <NUM_LIT:1.0> ) ) <EOL> self . failIf ( operator . gt ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . failIf ( operator . gt ( <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> def test_abs ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . abs ) <EOL> self . failUnlessRaises ( TypeError , operator . abs , None ) <EOL> self . failUnless ( operator . abs ( - <NUM_LIT:1> ) == <NUM_LIT:1> ) <EOL> self . failUnless ( operator . abs ( <NUM_LIT:1> ) == <NUM_LIT:1> ) <EOL> def test_add ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . add ) <EOL> self . failUnlessRaises ( TypeError , operator . add , None , None ) <EOL> self . failUnless ( operator . add ( <NUM_LIT:3> , <NUM_LIT:4> ) == <NUM_LIT:7> ) <EOL> def test_bitwise_and ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . and_ ) <EOL> self . failUnlessRaises ( TypeError , operator . and_ , None , None ) <EOL> self . failUnless ( operator . and_ ( <NUM_LIT> , <NUM_LIT> ) == <NUM_LIT> ) <EOL> def test_concat ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . concat ) <EOL> self . failUnlessRaises ( TypeError , operator . concat , None , None ) <EOL> self . failUnless ( operator . concat ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' ) <EOL> self . failUnless ( operator . concat ( [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ) == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> self . failUnless ( operator . concat ( Seq1 ( [ <NUM_LIT:5> , <NUM_LIT:6> ] ) , Seq1 ( [ <NUM_LIT:7> ] ) ) == [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) <EOL> self . failUnless ( operator . concat ( Seq2 ( [ <NUM_LIT:5> , <NUM_LIT:6> ] ) , Seq2 ( [ <NUM_LIT:7> ] ) ) == [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) <EOL> if not test_support . is_jython : <EOL> self . failUnlessRaises ( TypeError , operator . concat , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_countOf ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . countOf ) <EOL> self . failUnlessRaises ( TypeError , operator . countOf , None , None ) <EOL> self . failUnless ( operator . countOf ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> ] , <NUM_LIT:3> ) == <NUM_LIT:1> ) <EOL> self . failUnless ( operator . countOf ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> ] , <NUM_LIT:5> ) == <NUM_LIT:0> ) <EOL> def test_delitem ( self ) : <EOL> a = [ <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> self . failUnlessRaises ( TypeError , operator . delitem , a ) <EOL> self . failUnlessRaises ( TypeError , operator . delitem , a , None ) <EOL> self . failUnless ( operator . delitem ( a , <NUM_LIT:1> ) is None ) <EOL> self . assert_ ( a == [ <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> def test_delslice ( self ) : <EOL> a = range ( <NUM_LIT:10> ) <EOL> self . failUnlessRaises ( TypeError , operator . delslice , a ) <EOL> self . failUnlessRaises ( TypeError , operator . delslice , a , None , None ) <EOL> self . failUnless ( operator . delslice ( a , <NUM_LIT:2> , <NUM_LIT:8> ) is None ) <EOL> self . assert_ ( a == [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:9> ] ) <EOL> operator . delslice ( a , <NUM_LIT:0> , test_support . MAX_Py_ssize_t ) <EOL> self . assert_ ( a == [ ] ) <EOL> def test_div ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . div , <NUM_LIT:5> ) <EOL> self . failUnlessRaises ( TypeError , operator . div , None , None ) <EOL> self . failUnless ( operator . floordiv ( <NUM_LIT:5> , <NUM_LIT:2> ) == <NUM_LIT:2> ) <EOL> def test_floordiv ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . floordiv , <NUM_LIT:5> ) <EOL> self . failUnlessRaises ( TypeError , operator . floordiv , None , None ) <EOL> self . failUnless ( operator . floordiv ( <NUM_LIT:5> , <NUM_LIT:2> ) == <NUM_LIT:2> ) <EOL> def test_truediv ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . truediv , <NUM_LIT:5> ) <EOL> self . failUnlessRaises ( TypeError , operator . truediv , None , None ) <EOL> self . failUnless ( operator . truediv ( <NUM_LIT:5> , <NUM_LIT:2> ) == <NUM_LIT> ) <EOL> def test_getitem ( self ) : <EOL> a = range ( <NUM_LIT:10> ) <EOL> self . failUnlessRaises ( TypeError , operator . getitem ) <EOL> self . failUnlessRaises ( TypeError , operator . getitem , a , None ) <EOL> self . failUnless ( operator . getitem ( a , <NUM_LIT:2> ) == <NUM_LIT:2> ) <EOL> def test_getslice ( self ) : <EOL> a = range ( <NUM_LIT:10> ) <EOL> self . failUnlessRaises ( TypeError , operator . getslice ) <EOL> self . failUnlessRaises ( TypeError , operator . getslice , a , None , None ) <EOL> self . failUnless ( operator . getslice ( a , <NUM_LIT:4> , <NUM_LIT:6> ) == [ <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> b = operator . getslice ( a , <NUM_LIT:0> , test_support . MAX_Py_ssize_t ) <EOL> self . assert_ ( b == a ) <EOL> def test_indexOf ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . indexOf ) <EOL> self . failUnlessRaises ( TypeError , operator . indexOf , None , None ) <EOL> self . failUnless ( operator . indexOf ( [ <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] , <NUM_LIT:3> ) == <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , operator . indexOf , [ <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> def test_invert ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . invert ) <EOL> self . failUnlessRaises ( TypeError , operator . invert , None ) <EOL> self . failUnless ( operator . inv ( <NUM_LIT:4> ) == - <NUM_LIT:5> ) <EOL> def test_isCallable ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . isCallable ) <EOL> class C : <EOL> pass <EOL> def check ( self , o , v ) : <EOL> self . assert_ ( operator . isCallable ( o ) == callable ( o ) == v ) <EOL> check ( self , <NUM_LIT:4> , <NUM_LIT:0> ) <EOL> check ( self , operator . isCallable , <NUM_LIT:1> ) <EOL> check ( self , C , <NUM_LIT:1> ) <EOL> check ( self , C ( ) , <NUM_LIT:0> ) <EOL> def test_isMappingType ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . isMappingType ) <EOL> self . failIf ( operator . isMappingType ( <NUM_LIT:1> ) ) <EOL> self . failIf ( operator . isMappingType ( operator . isMappingType ) ) <EOL> self . failUnless ( operator . isMappingType ( operator . __dict__ ) ) <EOL> self . failUnless ( operator . isMappingType ( { } ) ) <EOL> def test_isNumberType ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . isNumberType ) <EOL> self . failUnless ( operator . isNumberType ( <NUM_LIT:8> ) ) <EOL> self . failUnless ( operator . isNumberType ( <NUM_LIT> ) ) <EOL> self . failUnless ( operator . isNumberType ( <NUM_LIT:8> L ) ) <EOL> self . failUnless ( operator . isNumberType ( <NUM_LIT> ) ) <EOL> self . failIf ( operator . isNumberType ( dir ( ) ) ) <EOL> def test_isSequenceType ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . isSequenceType ) <EOL> self . failUnless ( operator . isSequenceType ( dir ( ) ) ) <EOL> self . failUnless ( operator . isSequenceType ( ( ) ) ) <EOL> self . failUnless ( operator . isSequenceType ( xrange ( <NUM_LIT:10> ) ) ) <EOL> self . failUnless ( operator . isSequenceType ( '<STR_LIT>' ) ) <EOL> self . failIf ( operator . isSequenceType ( <NUM_LIT:3> ) ) <EOL> class Dict ( dict ) : pass <EOL> self . failIf ( operator . isSequenceType ( Dict ( ) ) ) <EOL> def test_lshift ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . lshift ) <EOL> self . failUnlessRaises ( TypeError , operator . lshift , None , <NUM_LIT> ) <EOL> self . failUnless ( operator . lshift ( <NUM_LIT:5> , <NUM_LIT:1> ) == <NUM_LIT:10> ) <EOL> self . failUnless ( operator . lshift ( <NUM_LIT:5> , <NUM_LIT:0> ) == <NUM_LIT:5> ) <EOL> self . assertRaises ( ValueError , operator . lshift , <NUM_LIT:2> , - <NUM_LIT:1> ) <EOL> def test_mod ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . mod ) <EOL> self . failUnlessRaises ( TypeError , operator . mod , None , <NUM_LIT> ) <EOL> self . failUnless ( operator . mod ( <NUM_LIT:5> , <NUM_LIT:2> ) == <NUM_LIT:1> ) <EOL> def test_mul ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . mul ) <EOL> self . failUnlessRaises ( TypeError , operator . mul , None , None ) <EOL> self . failUnless ( operator . mul ( <NUM_LIT:5> , <NUM_LIT:2> ) == <NUM_LIT:10> ) <EOL> def test_neg ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . neg ) <EOL> self . failUnlessRaises ( TypeError , operator . neg , None ) <EOL> self . failUnless ( operator . neg ( <NUM_LIT:5> ) == - <NUM_LIT:5> ) <EOL> self . failUnless ( operator . neg ( - <NUM_LIT:5> ) == <NUM_LIT:5> ) <EOL> self . failUnless ( operator . neg ( <NUM_LIT:0> ) == <NUM_LIT:0> ) <EOL> self . failUnless ( operator . neg ( - <NUM_LIT:0> ) == <NUM_LIT:0> ) <EOL> def test_bitwise_or ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . or_ ) <EOL> self . failUnlessRaises ( TypeError , operator . or_ , None , None ) <EOL> self . failUnless ( operator . or_ ( <NUM_LIT> , <NUM_LIT> ) == <NUM_LIT> ) <EOL> def test_pos ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . pos ) <EOL> self . failUnlessRaises ( TypeError , operator . pos , None ) <EOL> self . failUnless ( operator . pos ( <NUM_LIT:5> ) == <NUM_LIT:5> ) <EOL> self . failUnless ( operator . pos ( - <NUM_LIT:5> ) == - <NUM_LIT:5> ) <EOL> self . failUnless ( operator . pos ( <NUM_LIT:0> ) == <NUM_LIT:0> ) <EOL> self . failUnless ( operator . pos ( - <NUM_LIT:0> ) == <NUM_LIT:0> ) <EOL> def test_pow ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . pow ) <EOL> self . failUnlessRaises ( TypeError , operator . pow , None , None ) <EOL> self . failUnless ( operator . pow ( <NUM_LIT:3> , <NUM_LIT:5> ) == <NUM_LIT:3> ** <NUM_LIT:5> ) <EOL> self . failUnless ( operator . __pow__ ( <NUM_LIT:3> , <NUM_LIT:5> ) == <NUM_LIT:3> ** <NUM_LIT:5> ) <EOL> self . assertRaises ( TypeError , operator . pow , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , operator . pow , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> def test_repeat ( self ) : <EOL> a = range ( <NUM_LIT:3> ) <EOL> self . failUnlessRaises ( TypeError , operator . repeat ) <EOL> self . failUnlessRaises ( TypeError , operator . repeat , a , None ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:2> ) == a + a ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:1> ) == a ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:0> ) == [ ] ) <EOL> a = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:2> ) == a + a ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:1> ) == a ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:0> ) == ( ) ) <EOL> a = '<STR_LIT>' <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:2> ) == a + a ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:1> ) == a ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:0> ) == '<STR_LIT>' ) <EOL> a = Seq1 ( [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:2> ) == [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:1> ) == [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:0> ) == [ ] ) <EOL> a = Seq2 ( [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:2> ) == [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:1> ) == [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> self . failUnless ( operator . repeat ( a , <NUM_LIT:0> ) == [ ] ) <EOL> if not test_support . is_jython : <EOL> self . failUnlessRaises ( TypeError , operator . repeat , <NUM_LIT:6> , <NUM_LIT:7> ) <EOL> def test_rshift ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . rshift ) <EOL> self . failUnlessRaises ( TypeError , operator . rshift , None , <NUM_LIT> ) <EOL> self . failUnless ( operator . rshift ( <NUM_LIT:5> , <NUM_LIT:1> ) == <NUM_LIT:2> ) <EOL> self . failUnless ( operator . rshift ( <NUM_LIT:5> , <NUM_LIT:0> ) == <NUM_LIT:5> ) <EOL> self . assertRaises ( ValueError , operator . rshift , <NUM_LIT:2> , - <NUM_LIT:1> ) <EOL> def test_contains ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . contains ) <EOL> self . failUnlessRaises ( TypeError , operator . contains , None , None ) <EOL> self . failUnless ( operator . contains ( range ( <NUM_LIT:4> ) , <NUM_LIT:2> ) ) <EOL> self . failIf ( operator . contains ( range ( <NUM_LIT:4> ) , <NUM_LIT:5> ) ) <EOL> self . failUnless ( operator . sequenceIncludes ( range ( <NUM_LIT:4> ) , <NUM_LIT:2> ) ) <EOL> self . failIf ( operator . sequenceIncludes ( range ( <NUM_LIT:4> ) , <NUM_LIT:5> ) ) <EOL> def test_setitem ( self ) : <EOL> a = range ( <NUM_LIT:3> ) <EOL> self . failUnlessRaises ( TypeError , operator . setitem , a ) <EOL> self . failUnlessRaises ( TypeError , operator . setitem , a , None , None ) <EOL> self . failUnless ( operator . setitem ( a , <NUM_LIT:0> , <NUM_LIT:2> ) is None ) <EOL> self . assert_ ( a == [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertRaises ( IndexError , operator . setitem , a , <NUM_LIT:4> , <NUM_LIT:2> ) <EOL> def test_setslice ( self ) : <EOL> a = range ( <NUM_LIT:4> ) <EOL> self . failUnlessRaises ( TypeError , operator . setslice , a ) <EOL> self . failUnlessRaises ( TypeError , operator . setslice , a , None , None , None ) <EOL> self . failUnless ( operator . setslice ( a , <NUM_LIT:1> , <NUM_LIT:3> , [ <NUM_LIT:2> , <NUM_LIT:1> ] ) is None ) <EOL> self . assert_ ( a == [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> operator . setslice ( a , <NUM_LIT:0> , test_support . MAX_Py_ssize_t , [ ] ) <EOL> self . assert_ ( a == [ ] ) <EOL> def test_sub ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . sub ) <EOL> self . failUnlessRaises ( TypeError , operator . sub , None , None ) <EOL> self . failUnless ( operator . sub ( <NUM_LIT:5> , <NUM_LIT:2> ) == <NUM_LIT:3> ) <EOL> def test_truth ( self ) : <EOL> class C ( object ) : <EOL> def __nonzero__ ( self ) : <EOL> raise SyntaxError <EOL> self . failUnlessRaises ( TypeError , operator . truth ) <EOL> self . failUnlessRaises ( SyntaxError , operator . truth , C ( ) ) <EOL> self . failUnless ( operator . truth ( <NUM_LIT:5> ) ) <EOL> self . failUnless ( operator . truth ( [ <NUM_LIT:0> ] ) ) <EOL> self . failIf ( operator . truth ( <NUM_LIT:0> ) ) <EOL> self . failIf ( operator . truth ( [ ] ) ) <EOL> def test_bitwise_xor ( self ) : <EOL> self . failUnlessRaises ( TypeError , operator . xor ) <EOL> self . failUnlessRaises ( TypeError , operator . xor , None , None ) <EOL> self . failUnless ( operator . xor ( <NUM_LIT> , <NUM_LIT> ) == <NUM_LIT> ) <EOL> def test_is ( self ) : <EOL> a = b = '<STR_LIT>' <EOL> c = a [ : <NUM_LIT:3> ] + b [ <NUM_LIT:3> : ] <EOL> self . failUnlessRaises ( TypeError , operator . is_ ) <EOL> self . failUnless ( operator . is_ ( a , b ) ) <EOL> self . failIf ( operator . is_ ( a , c ) ) <EOL> def test_is_not ( self ) : <EOL> a = b = '<STR_LIT>' <EOL> c = a [ : <NUM_LIT:3> ] + b [ <NUM_LIT:3> : ] <EOL> self . failUnlessRaises ( TypeError , operator . is_not ) <EOL> self . failIf ( operator . is_not ( a , b ) ) <EOL> self . failUnless ( operator . is_not ( a , c ) ) <EOL> def test_attrgetter ( self ) : <EOL> class A : <EOL> pass <EOL> a = A ( ) <EOL> a . name = '<STR_LIT>' <EOL> f = operator . attrgetter ( '<STR_LIT:name>' ) <EOL> self . assertEqual ( f ( a ) , '<STR_LIT>' ) <EOL> f = operator . attrgetter ( '<STR_LIT>' ) <EOL> self . assertRaises ( AttributeError , f , a ) <EOL> f = operator . attrgetter ( <NUM_LIT:2> ) <EOL> self . assertRaises ( TypeError , f , a ) <EOL> self . assertRaises ( TypeError , operator . attrgetter ) <EOL> record = A ( ) <EOL> record . x = '<STR_LIT:X>' <EOL> record . y = '<STR_LIT:Y>' <EOL> record . z = '<STR_LIT>' <EOL> self . assertEqual ( operator . attrgetter ( '<STR_LIT:x>' , '<STR_LIT:z>' , '<STR_LIT:y>' ) ( record ) , ( '<STR_LIT:X>' , '<STR_LIT>' , '<STR_LIT:Y>' ) ) <EOL> self . assertRaises ( TypeError , operator . attrgetter ( '<STR_LIT:x>' , ( ) , '<STR_LIT:y>' ) , record ) <EOL> class C ( object ) : <EOL> def __getattr ( self , name ) : <EOL> raise SyntaxError <EOL> self . failUnlessRaises ( AttributeError , operator . attrgetter ( '<STR_LIT:foo>' ) , C ( ) ) <EOL> def test_itemgetter ( self ) : <EOL> a = '<STR_LIT>' <EOL> f = operator . itemgetter ( <NUM_LIT:2> ) <EOL> self . assertEqual ( f ( a ) , '<STR_LIT:C>' ) <EOL> f = operator . itemgetter ( <NUM_LIT:10> ) <EOL> self . assertRaises ( IndexError , f , a ) <EOL> class C ( object ) : <EOL> def __getitem ( self , name ) : <EOL> raise SyntaxError <EOL> self . failUnlessRaises ( TypeError , operator . itemgetter ( <NUM_LIT> ) , C ( ) ) <EOL> f = operator . itemgetter ( '<STR_LIT:name>' ) <EOL> self . assertRaises ( TypeError , f , a ) <EOL> self . assertRaises ( TypeError , operator . itemgetter ) <EOL> d = dict ( key = '<STR_LIT>' ) <EOL> f = operator . itemgetter ( '<STR_LIT:key>' ) <EOL> self . assertEqual ( f ( d ) , '<STR_LIT>' ) <EOL> f = operator . itemgetter ( '<STR_LIT>' ) <EOL> self . assertRaises ( KeyError , f , d ) <EOL> inventory = [ ( '<STR_LIT>' , <NUM_LIT:3> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) , ( '<STR_LIT>' , <NUM_LIT:5> ) , ( '<STR_LIT>' , <NUM_LIT:1> ) ] <EOL> getcount = operator . itemgetter ( <NUM_LIT:1> ) <EOL> self . assertEqual ( map ( getcount , inventory ) , [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:1> ] ) <EOL> self . assertEqual ( sorted ( inventory , key = getcount ) , <EOL> [ ( '<STR_LIT>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) , ( '<STR_LIT>' , <NUM_LIT:3> ) , ( '<STR_LIT>' , <NUM_LIT:5> ) ] ) <EOL> data = map ( str , range ( <NUM_LIT:20> ) ) <EOL> self . assertEqual ( operator . itemgetter ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:5> ) ( data ) , ( '<STR_LIT:2>' , '<STR_LIT>' , '<STR_LIT:5>' ) ) <EOL> self . assertRaises ( TypeError , operator . itemgetter ( <NUM_LIT:2> , '<STR_LIT:x>' , <NUM_LIT:5> ) , data ) <EOL> def test_inplace ( self ) : <EOL> class C ( object ) : <EOL> def __iadd__ ( self , other ) : return "<STR_LIT>" <EOL> def __iand__ ( self , other ) : return "<STR_LIT>" <EOL> def __idiv__ ( self , other ) : return "<STR_LIT>" <EOL> def __ifloordiv__ ( self , other ) : return "<STR_LIT>" <EOL> def __ilshift__ ( self , other ) : return "<STR_LIT>" <EOL> def __imod__ ( self , other ) : return "<STR_LIT>" <EOL> def __imul__ ( self , other ) : return "<STR_LIT>" <EOL> def __ior__ ( self , other ) : return "<STR_LIT>" <EOL> def __ipow__ ( self , other ) : return "<STR_LIT>" <EOL> def __irshift__ ( self , other ) : return "<STR_LIT>" <EOL> def __isub__ ( self , other ) : return "<STR_LIT>" <EOL> def __itruediv__ ( self , other ) : return "<STR_LIT>" <EOL> def __ixor__ ( self , other ) : return "<STR_LIT>" <EOL> def __getitem__ ( self , other ) : return <NUM_LIT:5> <EOL> c = C ( ) <EOL> self . assertEqual ( operator . iadd ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . iand ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . idiv ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . ifloordiv ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . ilshift ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . imod ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . imul ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . ior ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . ipow ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . irshift ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . isub ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . itruediv ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . ixor ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . iconcat ( c , c ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . irepeat ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __iadd__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __iand__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __idiv__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __ifloordiv__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __ilshift__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __imod__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __imul__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __ior__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __ipow__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __irshift__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __isub__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __itruediv__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __ixor__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __iconcat__ ( c , c ) , "<STR_LIT>" ) <EOL> self . assertEqual ( operator . __irepeat__ ( c , <NUM_LIT:5> ) , "<STR_LIT>" ) <EOL> def test_main ( verbose = None ) : <EOL> import sys <EOL> test_classes = ( <EOL> OperatorTestCase , <EOL> ) <EOL> test_support . run_unittest ( * test_classes ) <EOL> if verbose and hasattr ( sys , "<STR_LIT>" ) : <EOL> import gc <EOL> counts = [ None ] * <NUM_LIT:5> <EOL> for i in xrange ( len ( counts ) ) : <EOL> test_support . run_unittest ( * test_classes ) <EOL> gc . collect ( ) <EOL> counts [ i ] = sys . gettotalrefcount ( ) <EOL> print counts <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( verbose = True ) </s>
