<s> from test . test_support import verbose , TestFailed , verify <EOL> import types <EOL> class F : <EOL> def a ( self ) : <EOL> pass <EOL> def b ( ) : <EOL> '<STR_LIT>' <EOL> pass <EOL> verify ( b . __module__ == __name__ ) <EOL> verify ( verify . __module__ == "<STR_LIT>" ) <EOL> try : <EOL> b . publish <EOL> except AttributeError : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> if b . __dict__ < > { } : <EOL> raise TestFailed , '<STR_LIT>' <EOL> b . publish = <NUM_LIT:1> <EOL> if b . publish < > <NUM_LIT:1> : <EOL> raise TestFailed , '<STR_LIT>' <EOL> docstring = '<STR_LIT>' <EOL> b . __doc__ = docstring <EOL> if b . __doc__ < > docstring : <EOL> raise TestFailed , '<STR_LIT>' <EOL> if '<STR_LIT>' not in dir ( b ) : <EOL> raise TestFailed , '<STR_LIT>' <EOL> try : <EOL> del b . __dict__ <EOL> except TypeError : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> b . publish = <NUM_LIT:1> <EOL> try : <EOL> b . __dict__ = None <EOL> except TypeError : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> d = { '<STR_LIT:hello>' : '<STR_LIT>' } <EOL> b . __dict__ = d <EOL> if b . func_dict is not d : <EOL> raise TestFailed , '<STR_LIT>' <EOL> if b . hello < > '<STR_LIT>' : <EOL> raise TestFailed , '<STR_LIT>' <EOL> f1 = F ( ) <EOL> f2 = F ( ) <EOL> try : <EOL> F . a . publish <EOL> except AttributeError : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> try : <EOL> f1 . a . publish <EOL> except AttributeError : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> try : <EOL> F . a . publish = <NUM_LIT:1> <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> F . a . im_func . publish = <NUM_LIT:1> <EOL> if F . a . publish < > <NUM_LIT:1> : <EOL> raise TestFailed , '<STR_LIT>' <EOL> if f1 . a . publish < > <NUM_LIT:1> : <EOL> raise TestFailed , '<STR_LIT>' <EOL> if f2 . a . publish < > <NUM_LIT:1> : <EOL> raise TestFailed , '<STR_LIT>' <EOL> if '<STR_LIT>' not in dir ( F . a ) : <EOL> raise TestFailed , '<STR_LIT>' <EOL> try : <EOL> f1 . a . publish = <NUM_LIT:0> <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> try : <EOL> F . a . myclass = F <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> F . a . im_func . myclass = F <EOL> f1 . a . myclass <EOL> f2 . a . myclass <EOL> f1 . a . myclass <EOL> F . a . myclass <EOL> if f1 . a . myclass is not f2 . a . myclass or f1 . a . myclass is not F . a . myclass : <EOL> raise TestFailed , '<STR_LIT>' <EOL> try : <EOL> F . a . __dict__ = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed , '<STR_LIT>' <EOL> F . a . im_func . __dict__ = { '<STR_LIT>' : <NUM_LIT:11> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } <EOL> if f1 . a . two < > <NUM_LIT> : <EOL> raise TestFailed , '<STR_LIT>' <EOL> from UserDict import UserDict <EOL> d = UserDict ( { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } ) <EOL> try : <EOL> F . a . __dict__ = d <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed <EOL> if f2 . a . one < > f1 . a . one < > F . a . one < > <NUM_LIT:11> : <EOL> raise TestFailed <EOL> import new <EOL> F . id = new . instancemethod ( id , None , F ) <EOL> eff = F ( ) <EOL> if eff . id ( ) < > id ( eff ) : <EOL> raise TestFailed <EOL> try : <EOL> F . id . foo <EOL> except AttributeError : pass <EOL> else : raise TestFailed <EOL> try : <EOL> F . id . foo = <NUM_LIT:12> <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed <EOL> try : <EOL> F . id . foo <EOL> except AttributeError : pass <EOL> else : raise TestFailed <EOL> try : <EOL> eff . id . foo <EOL> except AttributeError : pass <EOL> else : raise TestFailed <EOL> try : <EOL> eff . id . foo = <NUM_LIT:12> <EOL> except ( AttributeError , TypeError ) : pass <EOL> else : raise TestFailed <EOL> try : <EOL> eff . id . foo <EOL> except AttributeError : pass <EOL> else : raise TestFailed <EOL> def another ( ) : <EOL> pass <EOL> try : <EOL> del another . __dict__ <EOL> except TypeError : pass <EOL> else : raise TestFailed <EOL> try : <EOL> del another . func_dict <EOL> except TypeError : pass <EOL> else : raise TestFailed <EOL> try : <EOL> another . func_dict = None <EOL> except TypeError : pass <EOL> else : raise TestFailed <EOL> try : <EOL> del another . bar <EOL> except AttributeError : pass <EOL> else : raise TestFailed <EOL> del another . func_defaults <EOL> def foo ( ) : <EOL> pass <EOL> def bar ( ) : <EOL> pass <EOL> def temp ( ) : <EOL> print <NUM_LIT:1> <EOL> if foo == bar : <EOL> raise TestFailed <EOL> d = { } <EOL> d [ foo ] = <NUM_LIT:1> <EOL> foo . func_code = temp . func_code <EOL> d [ foo ] <EOL> def cantset ( obj , name , value , exception = ( AttributeError , TypeError ) ) : <EOL> verify ( hasattr ( obj , name ) ) <EOL> try : <EOL> setattr ( obj , name , value ) <EOL> except exception : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" % ( name , value ) <EOL> try : <EOL> delattr ( obj , name ) <EOL> except ( AttributeError , TypeError ) : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" % name <EOL> def test_func_closure ( ) : <EOL> a = <NUM_LIT:12> <EOL> def f ( ) : print a <EOL> c = f . func_closure <EOL> verify ( isinstance ( c , tuple ) ) <EOL> verify ( len ( c ) == <NUM_LIT:1> ) <EOL> verify ( c [ <NUM_LIT:0> ] . __class__ . __name__ == "<STR_LIT>" ) <EOL> cantset ( f , "<STR_LIT>" , c ) <EOL> def test_empty_cell ( ) : <EOL> def f ( ) : print a <EOL> try : <EOL> f . func_closure [ <NUM_LIT:0> ] . cell_contents <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> a = <NUM_LIT:12> <EOL> def test_func_doc ( ) : <EOL> def f ( ) : pass <EOL> verify ( f . __doc__ is None ) <EOL> verify ( f . func_doc is None ) <EOL> f . __doc__ = "<STR_LIT:hello>" <EOL> verify ( f . __doc__ == "<STR_LIT:hello>" ) <EOL> verify ( f . func_doc == "<STR_LIT:hello>" ) <EOL> del f . __doc__ <EOL> verify ( f . __doc__ is None ) <EOL> verify ( f . func_doc is None ) <EOL> f . func_doc = "<STR_LIT>" <EOL> verify ( f . __doc__ == "<STR_LIT>" ) <EOL> verify ( f . func_doc == "<STR_LIT>" ) <EOL> del f . func_doc <EOL> verify ( f . func_doc is None ) <EOL> verify ( f . __doc__ is None ) <EOL> def test_func_globals ( ) : <EOL> def f ( ) : pass <EOL> verify ( f . func_globals is globals ( ) ) <EOL> cantset ( f , "<STR_LIT>" , globals ( ) ) <EOL> def test_func_name ( ) : <EOL> def f ( ) : pass <EOL> verify ( f . __name__ == "<STR_LIT:f>" ) <EOL> verify ( f . func_name == "<STR_LIT:f>" ) <EOL> f . __name__ = "<STR_LIT:g>" <EOL> verify ( f . __name__ == "<STR_LIT:g>" ) <EOL> verify ( f . func_name == "<STR_LIT:g>" ) <EOL> f . func_name = "<STR_LIT:h>" <EOL> verify ( f . __name__ == "<STR_LIT:h>" ) <EOL> verify ( f . func_name == "<STR_LIT:h>" ) <EOL> cantset ( f , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> cantset ( f , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> s = """<STR_LIT>""" <EOL> exec s in { '<STR_LIT>' : { } } <EOL> def test_func_code ( ) : <EOL> a = b = <NUM_LIT> <EOL> def f ( ) : pass <EOL> def g ( ) : print <NUM_LIT:12> <EOL> def f1 ( ) : print a <EOL> def g1 ( ) : print b <EOL> def f2 ( ) : print a , b <EOL> verify ( type ( f . func_code ) is types . CodeType ) <EOL> f . func_code = g . func_code <EOL> cantset ( f , "<STR_LIT>" , None ) <EOL> cantset ( f , "<STR_LIT>" , f1 . func_code , exception = ValueError ) <EOL> cantset ( f1 , "<STR_LIT>" , f . func_code , exception = ValueError ) <EOL> cantset ( f1 , "<STR_LIT>" , f2 . func_code , exception = ValueError ) <EOL> f1 . func_code = g1 . func_code <EOL> def test_func_defaults ( ) : <EOL> def f ( a , b ) : return ( a , b ) <EOL> verify ( f . func_defaults is None ) <EOL> f . func_defaults = ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> verify ( f . func_defaults == ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> verify ( f ( <NUM_LIT:10> ) == ( <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> def g ( a = <NUM_LIT:1> , b = <NUM_LIT:2> ) : return ( a , b ) <EOL> verify ( g . func_defaults == ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> del g . func_defaults <EOL> verify ( g . func_defaults is None ) <EOL> try : <EOL> g ( ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> raise TestFailed , "<STR_LIT>" <EOL> def test_func_dict ( ) : <EOL> def f ( ) : pass <EOL> a = f . __dict__ <EOL> b = f . func_dict <EOL> verify ( a == { } ) <EOL> verify ( a is b ) <EOL> f . hello = '<STR_LIT>' <EOL> verify ( a == { '<STR_LIT:hello>' : '<STR_LIT>' } ) <EOL> verify ( f . func_dict is a is f . __dict__ ) <EOL> f . func_dict = { } <EOL> verify ( not hasattr ( f , "<STR_LIT:hello>" ) ) <EOL> f . __dict__ = { '<STR_LIT>' : '<STR_LIT:hello>' } <EOL> verify ( f . world == "<STR_LIT:hello>" ) <EOL> verify ( f . __dict__ is f . func_dict == { '<STR_LIT>' : '<STR_LIT:hello>' } ) <EOL> cantset ( f , "<STR_LIT>" , None ) <EOL> cantset ( f , "<STR_LIT>" , None ) <EOL> def test_im_class ( ) : <EOL> class C : <EOL> def foo ( self ) : pass <EOL> verify ( C . foo . im_class is C ) <EOL> verify ( C ( ) . foo . im_class is C ) <EOL> cantset ( C . foo , "<STR_LIT>" , C ) <EOL> cantset ( C ( ) . foo , "<STR_LIT>" , C ) <EOL> def test_im_func ( ) : <EOL> def foo ( self ) : pass <EOL> class C : <EOL> pass <EOL> C . foo = foo <EOL> verify ( C . foo . im_func is foo ) <EOL> verify ( C ( ) . foo . im_func is foo ) <EOL> cantset ( C . foo , "<STR_LIT>" , foo ) <EOL> cantset ( C ( ) . foo , "<STR_LIT>" , foo ) <EOL> def test_im_self ( ) : <EOL> class C : <EOL> def foo ( self ) : pass <EOL> verify ( C . foo . im_self is None ) <EOL> c = C ( ) <EOL> verify ( c . foo . im_self is c ) <EOL> cantset ( C . foo , "<STR_LIT>" , None ) <EOL> cantset ( c . foo , "<STR_LIT>" , c ) <EOL> def test_im_dict ( ) : <EOL> class C : <EOL> def foo ( self ) : pass <EOL> foo . bar = <NUM_LIT> <EOL> verify ( C . foo . __dict__ == { '<STR_LIT:bar>' : <NUM_LIT> } ) <EOL> verify ( C ( ) . foo . __dict__ == { '<STR_LIT:bar>' : <NUM_LIT> } ) <EOL> cantset ( C . foo , "<STR_LIT>" , C . foo . __dict__ ) <EOL> cantset ( C ( ) . foo , "<STR_LIT>" , C . foo . __dict__ ) <EOL> def test_im_doc ( ) : <EOL> class C : <EOL> def foo ( self ) : "<STR_LIT:hello>" <EOL> verify ( C . foo . __doc__ == "<STR_LIT:hello>" ) <EOL> verify ( C ( ) . foo . __doc__ == "<STR_LIT:hello>" ) <EOL> cantset ( C . foo , "<STR_LIT>" , "<STR_LIT:hello>" ) <EOL> cantset ( C ( ) . foo , "<STR_LIT>" , "<STR_LIT:hello>" ) <EOL> def test_im_name ( ) : <EOL> class C : <EOL> def foo ( self ) : pass <EOL> verify ( C . foo . __name__ == "<STR_LIT:foo>" ) <EOL> verify ( C ( ) . foo . __name__ == "<STR_LIT:foo>" ) <EOL> cantset ( C . foo , "<STR_LIT>" , "<STR_LIT:foo>" ) <EOL> cantset ( C ( ) . foo , "<STR_LIT>" , "<STR_LIT:foo>" ) <EOL> def testmore ( ) : <EOL> test_func_closure ( ) <EOL> test_empty_cell ( ) <EOL> test_func_doc ( ) <EOL> test_func_globals ( ) <EOL> test_func_name ( ) <EOL> test_func_code ( ) <EOL> test_func_defaults ( ) <EOL> test_func_dict ( ) <EOL> test_im_class ( ) <EOL> test_im_func ( ) <EOL> test_im_self ( ) <EOL> test_im_dict ( ) <EOL> test_im_doc ( ) <EOL> test_im_name ( ) <EOL> testmore ( ) </s>
