<s> import unittest <EOL> from test import test_support <EOL> import os <EOL> class BoolTest ( unittest . TestCase ) : <EOL> def assertIs ( self , a , b ) : <EOL> self . assert_ ( a is b ) <EOL> def assertIsNot ( self , a , b ) : <EOL> self . assert_ ( a is not b ) <EOL> def test_subclass ( self ) : <EOL> try : <EOL> class C ( bool ) : <EOL> pass <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , int . __new__ , bool , <NUM_LIT:0> ) <EOL> def test_print ( self ) : <EOL> try : <EOL> fo = open ( test_support . TESTFN , "<STR_LIT:wb>" ) <EOL> print >> fo , False , True <EOL> fo . close ( ) <EOL> fo = open ( test_support . TESTFN , "<STR_LIT:rb>" ) <EOL> self . assertEqual ( fo . read ( ) , '<STR_LIT>' ) <EOL> finally : <EOL> fo . close ( ) <EOL> os . remove ( test_support . TESTFN ) <EOL> def test_repr ( self ) : <EOL> self . assertEqual ( repr ( False ) , '<STR_LIT:False>' ) <EOL> self . assertEqual ( repr ( True ) , '<STR_LIT:True>' ) <EOL> self . assertEqual ( eval ( repr ( False ) ) , False ) <EOL> self . assertEqual ( eval ( repr ( True ) ) , True ) <EOL> def test_str ( self ) : <EOL> self . assertEqual ( str ( False ) , '<STR_LIT:False>' ) <EOL> self . assertEqual ( str ( True ) , '<STR_LIT:True>' ) <EOL> def test_int ( self ) : <EOL> self . assertEqual ( int ( False ) , <NUM_LIT:0> ) <EOL> self . assertIsNot ( int ( False ) , False ) <EOL> self . assertEqual ( int ( True ) , <NUM_LIT:1> ) <EOL> self . assertIsNot ( int ( True ) , True ) <EOL> def test_math ( self ) : <EOL> self . assertEqual ( + False , <NUM_LIT:0> ) <EOL> self . assertIsNot ( + False , False ) <EOL> self . assertEqual ( - False , <NUM_LIT:0> ) <EOL> self . assertIsNot ( - False , False ) <EOL> self . assertEqual ( abs ( False ) , <NUM_LIT:0> ) <EOL> self . assertIsNot ( abs ( False ) , False ) <EOL> self . assertEqual ( + True , <NUM_LIT:1> ) <EOL> self . assertIsNot ( + True , True ) <EOL> self . assertEqual ( - True , - <NUM_LIT:1> ) <EOL> self . assertEqual ( abs ( True ) , <NUM_LIT:1> ) <EOL> self . assertIsNot ( abs ( True ) , True ) <EOL> self . assertEqual ( ~ False , - <NUM_LIT:1> ) <EOL> self . assertEqual ( ~ True , - <NUM_LIT:2> ) <EOL> self . assertEqual ( False + <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> self . assertEqual ( True + <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> self . assertEqual ( <NUM_LIT:2> + False , <NUM_LIT:2> ) <EOL> self . assertEqual ( <NUM_LIT:2> + True , <NUM_LIT:3> ) <EOL> self . assertEqual ( False + False , <NUM_LIT:0> ) <EOL> self . assertIsNot ( False + False , False ) <EOL> self . assertEqual ( False + True , <NUM_LIT:1> ) <EOL> self . assertIsNot ( False + True , True ) <EOL> self . assertEqual ( True + False , <NUM_LIT:1> ) <EOL> self . assertIsNot ( True + False , True ) <EOL> self . assertEqual ( True + True , <NUM_LIT:2> ) <EOL> self . assertEqual ( True - True , <NUM_LIT:0> ) <EOL> self . assertIsNot ( True - True , False ) <EOL> self . assertEqual ( False - False , <NUM_LIT:0> ) <EOL> self . assertIsNot ( False - False , False ) <EOL> self . assertEqual ( True - False , <NUM_LIT:1> ) <EOL> self . assertIsNot ( True - False , True ) <EOL> self . assertEqual ( False - True , - <NUM_LIT:1> ) <EOL> self . assertEqual ( True * <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assertEqual ( False * <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assertIsNot ( False * <NUM_LIT:1> , False ) <EOL> self . assertEqual ( True / <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assertIsNot ( True / <NUM_LIT:1> , True ) <EOL> self . assertEqual ( False / <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assertIsNot ( False / <NUM_LIT:1> , False ) <EOL> for b in False , True : <EOL> for i in <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> : <EOL> self . assertEqual ( b ** i , int ( b ) ** i ) <EOL> self . assertIsNot ( b ** i , bool ( int ( b ) ** i ) ) <EOL> for a in False , True : <EOL> for b in False , True : <EOL> self . assertIs ( a & b , bool ( int ( a ) & int ( b ) ) ) <EOL> self . assertIs ( a | b , bool ( int ( a ) | int ( b ) ) ) <EOL> self . assertIs ( a ^ b , bool ( int ( a ) ^ int ( b ) ) ) <EOL> self . assertEqual ( a & int ( b ) , int ( a ) & int ( b ) ) <EOL> self . assertIsNot ( a & int ( b ) , bool ( int ( a ) & int ( b ) ) ) <EOL> self . assertEqual ( a | int ( b ) , int ( a ) | int ( b ) ) <EOL> self . assertIsNot ( a | int ( b ) , bool ( int ( a ) | int ( b ) ) ) <EOL> self . assertEqual ( a ^ int ( b ) , int ( a ) ^ int ( b ) ) <EOL> self . assertIsNot ( a ^ int ( b ) , bool ( int ( a ) ^ int ( b ) ) ) <EOL> self . assertEqual ( int ( a ) & b , int ( a ) & int ( b ) ) <EOL> self . assertIsNot ( int ( a ) & b , bool ( int ( a ) & int ( b ) ) ) <EOL> self . assertEqual ( int ( a ) | b , int ( a ) | int ( b ) ) <EOL> self . assertIsNot ( int ( a ) | b , bool ( int ( a ) | int ( b ) ) ) <EOL> self . assertEqual ( int ( a ) ^ b , int ( a ) ^ int ( b ) ) <EOL> self . assertIsNot ( int ( a ) ^ b , bool ( int ( a ) ^ int ( b ) ) ) <EOL> self . assertIs ( <NUM_LIT:1> == <NUM_LIT:1> , True ) <EOL> self . assertIs ( <NUM_LIT:1> == <NUM_LIT:0> , False ) <EOL> self . assertIs ( <NUM_LIT:0> < <NUM_LIT:1> , True ) <EOL> self . assertIs ( <NUM_LIT:1> < <NUM_LIT:0> , False ) <EOL> self . assertIs ( <NUM_LIT:0> <= <NUM_LIT:0> , True ) <EOL> self . assertIs ( <NUM_LIT:1> <= <NUM_LIT:0> , False ) <EOL> self . assertIs ( <NUM_LIT:1> > <NUM_LIT:0> , True ) <EOL> self . assertIs ( <NUM_LIT:1> > <NUM_LIT:1> , False ) <EOL> self . assertIs ( <NUM_LIT:1> >= <NUM_LIT:1> , True ) <EOL> self . assertIs ( <NUM_LIT:0> >= <NUM_LIT:1> , False ) <EOL> self . assertIs ( <NUM_LIT:0> != <NUM_LIT:1> , True ) <EOL> self . assertIs ( <NUM_LIT:0> != <NUM_LIT:0> , False ) <EOL> x = [ <NUM_LIT:1> ] <EOL> self . assertIs ( x is x , True ) <EOL> self . assertIs ( x is not x , False ) <EOL> self . assertIs ( <NUM_LIT:1> in x , True ) <EOL> self . assertIs ( <NUM_LIT:0> in x , False ) <EOL> self . assertIs ( <NUM_LIT:1> not in x , False ) <EOL> self . assertIs ( <NUM_LIT:0> not in x , True ) <EOL> x = { <NUM_LIT:1> : <NUM_LIT:2> } <EOL> self . assertIs ( x is x , True ) <EOL> self . assertIs ( x is not x , False ) <EOL> self . assertIs ( <NUM_LIT:1> in x , True ) <EOL> self . assertIs ( <NUM_LIT:0> in x , False ) <EOL> self . assertIs ( <NUM_LIT:1> not in x , False ) <EOL> self . assertIs ( <NUM_LIT:0> not in x , True ) <EOL> self . assertIs ( not True , False ) <EOL> self . assertIs ( not False , True ) <EOL> def test_convert ( self ) : <EOL> self . assertRaises ( TypeError , bool , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertIs ( bool ( <NUM_LIT:10> ) , True ) <EOL> self . assertIs ( bool ( <NUM_LIT:1> ) , True ) <EOL> self . assertIs ( bool ( - <NUM_LIT:1> ) , True ) <EOL> self . assertIs ( bool ( <NUM_LIT:0> ) , False ) <EOL> self . assertIs ( bool ( "<STR_LIT:hello>" ) , True ) <EOL> self . assertIs ( bool ( "<STR_LIT>" ) , False ) <EOL> self . assertIs ( bool ( ) , False ) <EOL> def test_hasattr ( self ) : <EOL> self . assertIs ( hasattr ( [ ] , "<STR_LIT>" ) , True ) <EOL> self . assertIs ( hasattr ( [ ] , "<STR_LIT>" ) , False ) <EOL> def test_callable ( self ) : <EOL> self . assertIs ( callable ( len ) , True ) <EOL> self . assertIs ( callable ( <NUM_LIT:1> ) , False ) <EOL> def test_isinstance ( self ) : <EOL> self . assertIs ( isinstance ( True , bool ) , True ) <EOL> self . assertIs ( isinstance ( False , bool ) , True ) <EOL> self . assertIs ( isinstance ( True , int ) , True ) <EOL> self . assertIs ( isinstance ( False , int ) , True ) <EOL> self . assertIs ( isinstance ( <NUM_LIT:1> , bool ) , False ) <EOL> self . assertIs ( isinstance ( <NUM_LIT:0> , bool ) , False ) <EOL> def test_issubclass ( self ) : <EOL> self . assertIs ( issubclass ( bool , int ) , True ) <EOL> self . assertIs ( issubclass ( int , bool ) , False ) <EOL> def test_haskey ( self ) : <EOL> self . assertIs ( { } . has_key ( <NUM_LIT:1> ) , False ) <EOL> self . assertIs ( { <NUM_LIT:1> : <NUM_LIT:1> } . has_key ( <NUM_LIT:1> ) , True ) <EOL> def test_string ( self ) : <EOL> self . assertIs ( "<STR_LIT>" . endswith ( "<STR_LIT:z>" ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . endswith ( "<STR_LIT:x>" ) , False ) <EOL> self . assertIs ( "<STR_LIT>" . isalnum ( ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . isalnum ( ) , False ) <EOL> self . assertIs ( "<STR_LIT>" . isalpha ( ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . isalpha ( ) , False ) <EOL> self . assertIs ( "<STR_LIT>" . isdigit ( ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . isdigit ( ) , False ) <EOL> self . assertIs ( "<STR_LIT>" . islower ( ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . islower ( ) , False ) <EOL> self . assertIs ( "<STR_LIT:U+0020>" . isspace ( ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . isspace ( ) , False ) <EOL> self . assertIs ( "<STR_LIT:X>" . istitle ( ) , True ) <EOL> self . assertIs ( "<STR_LIT:x>" . istitle ( ) , False ) <EOL> self . assertIs ( "<STR_LIT>" . isupper ( ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . isupper ( ) , False ) <EOL> self . assertIs ( "<STR_LIT>" . startswith ( "<STR_LIT:x>" ) , True ) <EOL> self . assertIs ( "<STR_LIT>" . startswith ( "<STR_LIT:z>" ) , False ) <EOL> if test_support . have_unicode : <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . endswith ( unicode ( "<STR_LIT:z>" , '<STR_LIT:ascii>' ) ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . endswith ( unicode ( "<STR_LIT:x>" , '<STR_LIT:ascii>' ) ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isalnum ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isalnum ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isalpha ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isalpha ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isdecimal ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isdecimal ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isdigit ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isdigit ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . islower ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . islower ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isnumeric ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isnumeric ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT:U+0020>" , '<STR_LIT:ascii>' ) . isspace ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isspace ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT:X>" , '<STR_LIT:ascii>' ) . istitle ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT:x>" , '<STR_LIT:ascii>' ) . istitle ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isupper ( ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . isupper ( ) , False ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . startswith ( unicode ( "<STR_LIT:x>" , '<STR_LIT:ascii>' ) ) , True ) <EOL> self . assertIs ( unicode ( "<STR_LIT>" , '<STR_LIT:ascii>' ) . startswith ( unicode ( "<STR_LIT:z>" , '<STR_LIT:ascii>' ) ) , False ) <EOL> def test_boolean ( self ) : <EOL> self . assertEqual ( True & <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assert_ ( not isinstance ( True & <NUM_LIT:1> , bool ) ) <EOL> self . assertIs ( True & True , True ) <EOL> self . assertEqual ( True | <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assert_ ( not isinstance ( True | <NUM_LIT:1> , bool ) ) <EOL> self . assertIs ( True | True , True ) <EOL> self . assertEqual ( True ^ <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assert_ ( not isinstance ( True ^ <NUM_LIT:1> , bool ) ) <EOL> self . assertIs ( True ^ True , False ) <EOL> def test_fileclosed ( self ) : <EOL> try : <EOL> f = file ( test_support . TESTFN , "<STR_LIT:w>" ) <EOL> self . assertIs ( f . closed , False ) <EOL> f . close ( ) <EOL> self . assertIs ( f . closed , True ) <EOL> finally : <EOL> os . remove ( test_support . TESTFN ) <EOL> def test_operator ( self ) : <EOL> import operator <EOL> self . assertIs ( operator . truth ( <NUM_LIT:0> ) , False ) <EOL> self . assertIs ( operator . truth ( <NUM_LIT:1> ) , True ) <EOL> self . assertIs ( operator . isCallable ( <NUM_LIT:0> ) , False ) <EOL> self . assertIs ( operator . isCallable ( len ) , True ) <EOL> self . assertIs ( operator . isNumberType ( None ) , False ) <EOL> self . assertIs ( operator . isNumberType ( <NUM_LIT:0> ) , True ) <EOL> self . assertIs ( operator . not_ ( <NUM_LIT:1> ) , False ) <EOL> self . assertIs ( operator . not_ ( <NUM_LIT:0> ) , True ) <EOL> self . assertIs ( operator . isSequenceType ( <NUM_LIT:0> ) , False ) <EOL> self . assertIs ( operator . isSequenceType ( [ ] ) , True ) <EOL> self . assertIs ( operator . contains ( [ ] , <NUM_LIT:1> ) , False ) <EOL> self . assertIs ( operator . contains ( [ <NUM_LIT:1> ] , <NUM_LIT:1> ) , True ) <EOL> self . assertIs ( operator . isMappingType ( <NUM_LIT:1> ) , False ) <EOL> self . assertIs ( operator . isMappingType ( { } ) , True ) <EOL> self . assertIs ( operator . lt ( <NUM_LIT:0> , <NUM_LIT:0> ) , False ) <EOL> self . assertIs ( operator . lt ( <NUM_LIT:0> , <NUM_LIT:1> ) , True ) <EOL> self . assertIs ( operator . is_ ( True , True ) , True ) <EOL> self . assertIs ( operator . is_ ( True , False ) , False ) <EOL> self . assertIs ( operator . is_not ( True , True ) , False ) <EOL> self . assertIs ( operator . is_not ( True , False ) , True ) <EOL> def test_marshal ( self ) : <EOL> import marshal <EOL> self . assertIs ( marshal . loads ( marshal . dumps ( True ) ) , True ) <EOL> self . assertIs ( marshal . loads ( marshal . dumps ( False ) ) , False ) <EOL> def test_pickle ( self ) : <EOL> import pickle <EOL> self . assertIs ( pickle . loads ( pickle . dumps ( True ) ) , True ) <EOL> self . assertIs ( pickle . loads ( pickle . dumps ( False ) ) , False ) <EOL> self . assertIs ( pickle . loads ( pickle . dumps ( True , True ) ) , True ) <EOL> self . assertIs ( pickle . loads ( pickle . dumps ( False , True ) ) , False ) <EOL> def test_cpickle ( self ) : <EOL> import cPickle <EOL> self . assertIs ( cPickle . loads ( cPickle . dumps ( True ) ) , True ) <EOL> self . assertIs ( cPickle . loads ( cPickle . dumps ( False ) ) , False ) <EOL> self . assertIs ( cPickle . loads ( cPickle . dumps ( True , True ) ) , True ) <EOL> self . assertIs ( cPickle . loads ( cPickle . dumps ( False , True ) ) , False ) <EOL> def test_mixedpickle ( self ) : <EOL> import pickle , cPickle <EOL> self . assertIs ( pickle . loads ( cPickle . dumps ( True ) ) , True ) <EOL> self . assertIs ( pickle . loads ( cPickle . dumps ( False ) ) , False ) <EOL> self . assertIs ( pickle . loads ( cPickle . dumps ( True , True ) ) , True ) <EOL> self . assertIs ( pickle . loads ( cPickle . dumps ( False , True ) ) , False ) <EOL> self . assertIs ( cPickle . loads ( pickle . dumps ( True ) ) , True ) <EOL> self . assertIs ( cPickle . loads ( pickle . dumps ( False ) ) , False ) <EOL> self . assertIs ( cPickle . loads ( pickle . dumps ( True , True ) ) , True ) <EOL> self . assertIs ( cPickle . loads ( pickle . dumps ( False , True ) ) , False ) <EOL> def test_picklevalues ( self ) : <EOL> import pickle , cPickle <EOL> self . assertEqual ( pickle . dumps ( True ) , "<STR_LIT>" ) <EOL> self . assertEqual ( pickle . dumps ( False ) , "<STR_LIT>" ) <EOL> self . assertEqual ( cPickle . dumps ( True ) , "<STR_LIT>" ) <EOL> self . assertEqual ( cPickle . dumps ( False ) , "<STR_LIT>" ) <EOL> self . assertEqual ( pickle . dumps ( True , True ) , "<STR_LIT>" ) <EOL> self . assertEqual ( pickle . dumps ( False , True ) , "<STR_LIT>" ) <EOL> self . assertEqual ( cPickle . dumps ( True , True ) , "<STR_LIT>" ) <EOL> self . assertEqual ( cPickle . dumps ( False , True ) , "<STR_LIT>" ) <EOL> def test_convert_to_bool ( self ) : <EOL> check = lambda o : self . assertRaises ( TypeError , bool , o ) <EOL> class Foo ( object ) : <EOL> def __nonzero__ ( self ) : <EOL> return self <EOL> check ( Foo ( ) ) <EOL> class Bar ( object ) : <EOL> def __nonzero__ ( self ) : <EOL> return "<STR_LIT>" <EOL> check ( Bar ( ) ) <EOL> class Baz ( int ) : <EOL> def __nonzero__ ( self ) : <EOL> return self <EOL> check ( Baz ( ) ) <EOL> del BoolTest . test_convert_to_bool <EOL> del BoolTest . test_subclass <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( BoolTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
