<s> """<STR_LIT>""" <EOL> import types <EOL> import unittest <EOL> from test import test_support <EOL> class Old : <EOL> pass <EOL> class New ( object ) : <EOL> pass <EOL> old = Old ( ) <EOL> new = New ( ) <EOL> class TestDescrTestCase ( unittest . TestCase ) : <EOL> def test_class_dict_is_copy ( self ) : <EOL> class FooMeta ( type ) : <EOL> def __new__ ( meta , name , bases , class_dict ) : <EOL> cls = type . __new__ ( meta , name , bases , class_dict ) <EOL> self . assert_ ( '<STR_LIT:foo>' not in class_dict ) <EOL> cls . foo = '<STR_LIT:bar>' <EOL> self . assert_ ( '<STR_LIT:foo>' not in class_dict ) <EOL> return cls <EOL> class Foo ( object ) : <EOL> __metaclass__ = FooMeta <EOL> def test_descr___get__ ( self ) : <EOL> class Foo ( object ) : <EOL> __slots__ = '<STR_LIT:bar>' <EOL> def hello ( self ) : <EOL> pass <EOL> def hi ( self ) : <EOL> pass <EOL> hi = staticmethod ( hi ) <EOL> foo = Foo ( ) <EOL> foo . bar = '<STR_LIT>' <EOL> self . assertEqual ( Foo . bar . __get__ ( foo ) , '<STR_LIT>' ) <EOL> self . assertEqual ( Foo . bar . __get__ ( None , Foo ) , Foo . bar ) <EOL> bound = Foo . hello . __get__ ( foo ) <EOL> self . assert_ ( isinstance ( bound , types . MethodType ) ) <EOL> self . assert_ ( bound . im_self is foo ) <EOL> self . assertEqual ( Foo . hello . __get__ ( None , Foo ) , Foo . hello ) <EOL> bound = Foo . hi . __get__ ( foo ) <EOL> self . assert_ ( isinstance ( bound , types . MethodType ) ) <EOL> self . assert_ ( bound . im_self is foo ) <EOL> unbound = Foo . hi . __get__ ( None , foo ) <EOL> self . assert_ ( isinstance ( unbound , types . MethodType ) ) <EOL> self . assert_ ( unbound . im_self is None ) <EOL> def test_ints ( self ) : <EOL> class C ( int ) : <EOL> pass <EOL> try : <EOL> foo = int ( None ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . assert_ ( False , "<STR_LIT>" ) <EOL> try : <EOL> foo = C ( None ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . assert_ ( False , "<STR_LIT>" ) <EOL> def test_raising_custom_attribute_error ( self ) : <EOL> class RaisesCustomMsg ( object ) : <EOL> def __get__ ( self , instance , type ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> class CustomAttributeError ( AttributeError ) : pass <EOL> class RaisesCustomErr ( object ) : <EOL> def __get__ ( self , instance , type ) : <EOL> raise CustomAttributeError <EOL> class Foo ( object ) : <EOL> custom_msg = RaisesCustomMsg ( ) <EOL> custom_err = RaisesCustomErr ( ) <EOL> self . assertRaises ( CustomAttributeError , lambda : Foo ( ) . custom_err ) <EOL> try : <EOL> Foo ( ) . custom_msg <EOL> self . assert_ ( False ) <EOL> except AttributeError , e : <EOL> self . assertEquals ( "<STR_LIT>" , str ( e ) ) <EOL> class SubclassDescrTestCase ( unittest . TestCase ) : <EOL> def test_subclass_cmp_right_op ( self ) : <EOL> class B ( int ) : <EOL> def __ge__ ( self , other ) : <EOL> return "<STR_LIT>" <EOL> def __le__ ( self , other ) : <EOL> return "<STR_LIT>" <EOL> self . assertEqual ( B ( <NUM_LIT:1> ) >= <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT:1> >= B ( <NUM_LIT:1> ) , "<STR_LIT>" ) <EOL> class C ( object ) : <EOL> def __ge__ ( self , other ) : <EOL> return "<STR_LIT>" <EOL> def __le__ ( self , other ) : <EOL> return "<STR_LIT>" <EOL> self . assertEqual ( C ( ) >= <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT:1> >= C ( ) , "<STR_LIT>" ) <EOL> class D ( C ) : <EOL> def __ge__ ( self , other ) : <EOL> return "<STR_LIT>" <EOL> def __le__ ( self , other ) : <EOL> return "<STR_LIT>" <EOL> self . assertEqual ( D ( ) >= C ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( C ( ) >= D ( ) , "<STR_LIT>" ) <EOL> class E ( C ) : <EOL> pass <EOL> self . assertEqual ( E . __le__ , C . __le__ ) <EOL> self . assertEqual ( E ( ) >= <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT:1> >= E ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( E ( ) >= C ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( C ( ) >= E ( ) , "<STR_LIT>" ) <EOL> def test_subclass_binop ( self ) : <EOL> def raises ( exc , expected , callable , * args ) : <EOL> try : <EOL> callable ( * args ) <EOL> except exc , msg : <EOL> if str ( msg ) != expected : <EOL> self . assert_ ( False , "<STR_LIT>" % ( str ( msg ) , <EOL> expected ) ) <EOL> else : <EOL> self . assert_ ( False , "<STR_LIT>" % exc ) <EOL> class B ( object ) : <EOL> pass <EOL> class C ( object ) : <EOL> def __radd__ ( self , o ) : <EOL> return '<STR_LIT>' % ( o , ) <EOL> def __rmul__ ( self , o ) : <EOL> return '<STR_LIT>' % ( o , ) <EOL> mapping = [ ] <EOL> mapping . append ( ( lambda o : '<STR_LIT:foo>' + o , <EOL> TypeError , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> if test_support . is_jython : <EOL> mapping . append ( ( lambda o : u'<STR_LIT:foo>' + o , <EOL> TypeError , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> else : <EOL> mapping . append ( ( lambda o : u'<STR_LIT:foo>' + o , <EOL> TypeError , <EOL> '<STR_LIT>' , <EOL> "<STR_LIT>" ) ) <EOL> mapping . append ( ( lambda o : [ <NUM_LIT:1> , <NUM_LIT:2> ] + o , <EOL> TypeError , '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> mapping . append ( ( lambda o : ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) + o , <EOL> TypeError , '<STR_LIT>' , <EOL> "<STR_LIT>" ) ) <EOL> mapping . append ( ( lambda o : '<STR_LIT:foo>' * o , <EOL> TypeError , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> mapping . append ( ( lambda o : u'<STR_LIT:foo>' * o , <EOL> TypeError , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> mapping . append ( ( lambda o : [ <NUM_LIT:1> , <NUM_LIT:2> ] * o , <EOL> TypeError , "<STR_LIT>" , <EOL> '<STR_LIT>' ) ) <EOL> mapping . append ( ( lambda o : ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) * o , <EOL> TypeError , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> for func , bexc , bexc_msg , cresult in mapping : <EOL> raises ( bexc , bexc_msg , lambda : func ( B ( ) ) ) <EOL> self . assertEqual ( func ( C ( ) ) , cresult ) <EOL> class InPlaceTestCase ( unittest . TestCase ) : <EOL> def test_iadd ( self ) : <EOL> class Foo ( object ) : <EOL> def __add__ ( self , other ) : <EOL> return <NUM_LIT:1> <EOL> def __radd__ ( self , other ) : <EOL> return <NUM_LIT:2> <EOL> class Bar ( object ) : <EOL> pass <EOL> class Baz ( object ) : <EOL> def __iadd__ ( self , other ) : <EOL> return NotImplemented <EOL> foo = Foo ( ) <EOL> foo += Bar ( ) <EOL> self . assertEqual ( foo , <NUM_LIT:1> ) <EOL> bar = Bar ( ) <EOL> bar += Foo ( ) <EOL> self . assertEqual ( bar , <NUM_LIT:2> ) <EOL> baz = Baz ( ) <EOL> baz += Foo ( ) <EOL> self . assertEqual ( baz , <NUM_LIT:2> ) <EOL> def test_imul ( self ) : <EOL> class FooInplace ( list ) : <EOL> def __imul__ ( self , other ) : <EOL> return [ <NUM_LIT:1> ] <EOL> class Bar ( FooInplace ) : <EOL> def __mul__ ( self , other ) : <EOL> return [ <NUM_LIT:2> ] <EOL> foo = FooInplace ( ) <EOL> foo *= <NUM_LIT:3> <EOL> self . assertEqual ( foo , [ <NUM_LIT:1> ] ) <EOL> foo = Bar ( [ <NUM_LIT:3> ] ) <EOL> foo *= <NUM_LIT:3> <EOL> self . assertEqual ( foo , [ <NUM_LIT:1> ] ) <EOL> class Baz ( FooInplace ) : <EOL> def __mul__ ( self , other ) : <EOL> return [ <NUM_LIT:3> ] <EOL> baz = Baz ( ) <EOL> baz *= <NUM_LIT:3> <EOL> self . assertEqual ( baz , [ <NUM_LIT:1> ] ) <EOL> def test_list ( self ) : <EOL> class Foo ( list ) : <EOL> def __mul__ ( self , other ) : <EOL> return [ <NUM_LIT:1> ] <EOL> foo = Foo ( [ <NUM_LIT:2> ] ) <EOL> foo *= <NUM_LIT:3> <EOL> if test_support . is_jython : <EOL> self . assertEqual ( foo , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] ) <EOL> else : <EOL> self . assertEqual ( foo , [ <NUM_LIT:1> ] ) <EOL> class Bar ( object ) : <EOL> def __radd__ ( self , other ) : <EOL> return <NUM_LIT:1> <EOL> def __rmul__ ( self , other ) : <EOL> return <NUM_LIT:2> <EOL> l = [ ] <EOL> l += Bar ( ) <EOL> self . assertEqual ( l , <NUM_LIT:1> ) <EOL> l = [ ] <EOL> l *= Bar ( ) <EOL> self . assertEqual ( l , <NUM_LIT:2> ) <EOL> def test_iand ( self ) : <EOL> class Foo ( set ) : <EOL> def __and__ ( self , other ) : <EOL> return set ( [ <NUM_LIT:1> ] ) <EOL> foo = Foo ( ) <EOL> foo &= <NUM_LIT:3> <EOL> self . assertEqual ( foo , set ( [ <NUM_LIT:1> ] ) ) <EOL> class DescrExceptionsTestCase ( unittest . TestCase ) : <EOL> def test_hex ( self ) : <EOL> self . _test ( hex ) <EOL> def test_oct ( self ) : <EOL> self . _test ( oct ) <EOL> def test_other ( self ) : <EOL> for op in '<STR_LIT:->' , '<STR_LIT:+>' , '<STR_LIT>' : <EOL> try : <EOL> eval ( '<STR_LIT>' % op ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> self . _assert ( False , '<STR_LIT>' % op ) <EOL> try : <EOL> eval ( '<STR_LIT>' % op ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . _assert ( False , '<STR_LIT>' % op ) <EOL> def _test ( self , func ) : <EOL> self . assertRaises ( AttributeError , func , old ) <EOL> self . assertRaises ( TypeError , func , new ) <EOL> class GetAttrTestCase ( unittest . TestCase ) : <EOL> def test_raising_custom_attribute_error ( self ) : <EOL> class BarAttributeError ( AttributeError ) : pass <EOL> class Bar ( object ) : <EOL> def __getattr__ ( self , name ) : <EOL> raise BarAttributeError <EOL> class BarClassic : <EOL> def __getattr__ ( self , name ) : <EOL> raise BarAttributeError <EOL> class Foo ( object ) : <EOL> def __getattr__ ( self , name ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> class FooClassic : <EOL> def __getattr__ ( self , name ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> self . assertRaises ( BarAttributeError , lambda : Bar ( ) . x ) <EOL> self . assertRaises ( BarAttributeError , lambda : BarClassic ( ) . x ) <EOL> try : <EOL> Foo ( ) . x <EOL> self . assert_ ( False ) <EOL> except AttributeError , e : <EOL> self . assertEquals ( "<STR_LIT>" , str ( e ) ) <EOL> try : <EOL> FooClassic ( ) . x <EOL> self . assert_ ( False ) <EOL> except AttributeError , e : <EOL> self . assertEquals ( "<STR_LIT>" , str ( e ) ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( TestDescrTestCase , <EOL> SubclassDescrTestCase , <EOL> InPlaceTestCase , <EOL> DescrExceptionsTestCase , <EOL> GetAttrTestCase ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
