<s> from pypy . conftest import gettestobjspace <EOL> from pypy . interpreter import gateway <EOL> from pypy . interpreter import argument <EOL> import py <EOL> import sys <EOL> class FakeFunc ( object ) : <EOL> def __init__ ( self , space , name ) : <EOL> self . space = space <EOL> self . name = name <EOL> self . defs_w = [ ] <EOL> class TestBuiltinCode : <EOL> def test_signature ( self ) : <EOL> def c ( space , w_x , w_y , hello_w ) : <EOL> pass <EOL> code = gateway . BuiltinCode ( c , unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root , <EOL> '<STR_LIT>' ] ) <EOL> assert code . signature ( ) == argument . Signature ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , '<STR_LIT:hello>' , None ) <EOL> def d ( self , w_boo ) : <EOL> pass <EOL> code = gateway . BuiltinCode ( d , unwrap_spec = [ '<STR_LIT>' , <EOL> gateway . W_Root ] , self_type = gateway . Wrappable ) <EOL> assert code . signature ( ) == argument . Signature ( [ '<STR_LIT>' , '<STR_LIT>' ] , None , None ) <EOL> def e ( space , w_x , w_y , __args__ ) : <EOL> pass <EOL> code = gateway . BuiltinCode ( e , unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root , <EOL> gateway . Arguments ] ) <EOL> assert code . signature ( ) == argument . Signature ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , '<STR_LIT:args>' , '<STR_LIT>' ) <EOL> def f ( space , index ) : <EOL> pass <EOL> code = gateway . BuiltinCode ( f , unwrap_spec = [ gateway . ObjSpace , "<STR_LIT:index>" ] ) <EOL> assert code . signature ( ) == argument . Signature ( [ "<STR_LIT:index>" ] , None , None ) <EOL> def test_call ( self ) : <EOL> def c ( space , w_x , w_y , hello_w ) : <EOL> u = space . unwrap <EOL> w = space . wrap <EOL> assert len ( hello_w ) == <NUM_LIT:2> <EOL> assert u ( hello_w [ <NUM_LIT:0> ] ) == <NUM_LIT:0> <EOL> assert u ( hello_w [ <NUM_LIT:1> ] ) == True <EOL> return w ( ( u ( w_x ) - u ( w_y ) + len ( hello_w ) ) ) <EOL> code = gateway . BuiltinCode ( c , unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root , <EOL> '<STR_LIT>' ] ) <EOL> w = self . space . wrap <EOL> args = argument . Arguments ( self . space , [ w ( <NUM_LIT> ) , w ( <NUM_LIT> ) , w ( <NUM_LIT:0> ) , w ( True ) ] ) <EOL> w_result = code . funcrun ( FakeFunc ( self . space , "<STR_LIT:c>" ) , args ) <EOL> assert self . space . eq_w ( w_result , w ( <NUM_LIT> ) ) <EOL> def test_call_index ( self ) : <EOL> def c ( space , index ) : <EOL> assert type ( index ) is int <EOL> code = gateway . BuiltinCode ( c , unwrap_spec = [ gateway . ObjSpace , <EOL> "<STR_LIT:index>" ] ) <EOL> w = self . space . wrap <EOL> args = argument . Arguments ( self . space , [ w ( <NUM_LIT> ) ] ) <EOL> code . funcrun ( FakeFunc ( self . space , "<STR_LIT:c>" ) , args ) <EOL> def test_call_args ( self ) : <EOL> def c ( space , w_x , w_y , __args__ ) : <EOL> args_w , kwds_w = __args__ . unpack ( ) <EOL> u = space . unwrap <EOL> w = space . wrap <EOL> return w ( ( u ( w_x ) - u ( w_y ) + len ( args_w ) ) <EOL> * u ( kwds_w [ '<STR_LIT>' ] ) ) <EOL> code = gateway . BuiltinCode ( c , unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root , <EOL> gateway . Arguments ] ) <EOL> w = self . space . wrap <EOL> args = argument . Arguments ( self . space , [ w ( <NUM_LIT> ) , w ( <NUM_LIT> ) ] , [ ] , [ ] , <EOL> w_stararg = w ( ( <NUM_LIT:0> , True ) ) , <EOL> w_starstararg = w ( { '<STR_LIT>' : <NUM_LIT:10> } ) ) <EOL> w_result = code . funcrun ( FakeFunc ( self . space , "<STR_LIT:c>" ) , args ) <EOL> assert self . space . eq_w ( w_result , w ( <NUM_LIT> ) ) <EOL> class TestGateway : <EOL> def test_app2interp ( self ) : <EOL> w = self . space . wrap <EOL> def app_g3 ( a , b ) : <EOL> return a + b <EOL> g3 = gateway . app2interp_temp ( app_g3 ) <EOL> assert self . space . eq_w ( g3 ( self . space , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , w ( '<STR_LIT>' ) ) <EOL> def test_app2interp1 ( self ) : <EOL> w = self . space . wrap <EOL> def noapp_g3 ( a , b ) : <EOL> return a + b <EOL> g3 = gateway . app2interp_temp ( noapp_g3 , gateway . applevel_temp ) <EOL> assert self . space . eq_w ( g3 ( self . space , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , w ( '<STR_LIT>' ) ) <EOL> def test_app2interp2 ( self ) : <EOL> """<STR_LIT>""" <EOL> w = self . space . wrap <EOL> def noapp_g3 ( a , b ) : <EOL> return a + b <EOL> g3 = gateway . app2interp_temp ( noapp_g3 , gateway . applevelinterp_temp ) <EOL> assert self . space . eq_w ( g3 ( self . space , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , w ( '<STR_LIT>' ) ) <EOL> def test_app2interp_general_args ( self ) : <EOL> w = self . space . wrap <EOL> def app_general ( x , * args , ** kwds ) : <EOL> assert type ( args ) is tuple <EOL> assert type ( kwds ) is dict <EOL> return x + <NUM_LIT:10> * len ( args ) + <NUM_LIT:100> * len ( kwds ) <EOL> gg = gateway . app2interp_temp ( app_general ) <EOL> args = gateway . Arguments ( self . space , [ w ( <NUM_LIT:6> ) , w ( <NUM_LIT:7> ) ] ) <EOL> assert self . space . int_w ( gg ( self . space , w ( <NUM_LIT:3> ) , args ) ) == <NUM_LIT> <EOL> args = gateway . Arguments ( self . space , [ w ( <NUM_LIT:6> ) ] , [ '<STR_LIT:hello>' , '<STR_LIT>' ] , [ w ( <NUM_LIT:7> ) , w ( <NUM_LIT:8> ) ] ) <EOL> assert self . space . int_w ( gg ( self . space , w ( <NUM_LIT:3> ) , args ) ) == <NUM_LIT> <EOL> def test_interp2app ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3 ( space , w_a , w_b ) : <EOL> return space . add ( w_a , w_b ) <EOL> app_g3 = gateway . interp2app_temp ( g3 ) <EOL> w_app_g3 = space . wrap ( app_g3 ) <EOL> assert self . space . eq_w ( <EOL> space . call ( w_app_g3 , <EOL> space . newtuple ( [ w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ] ) , <EOL> space . newdict ( ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3 , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> def test_interp2app_unwrap_spec ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3 ( space , w_a , w_b ) : <EOL> return space . add ( w_a , w_b ) <EOL> app_g3 = gateway . interp2app_temp ( g3 , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root ] ) <EOL> w_app_g3 = space . wrap ( app_g3 ) <EOL> assert self . space . eq_w ( <EOL> space . call ( w_app_g3 , <EOL> space . newtuple ( [ w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ] ) , <EOL> space . newdict ( ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3 , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> def test_interp2app_unwrap_spec_bool ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g ( space , b ) : <EOL> return space . wrap ( b ) <EOL> app_g = gateway . interp2app ( g , unwrap_spec = [ gateway . ObjSpace , bool ] ) <EOL> app_g2 = gateway . interp2app ( g , unwrap_spec = [ gateway . ObjSpace , bool ] ) <EOL> assert app_g is app_g2 <EOL> w_app_g = space . wrap ( app_g ) <EOL> assert self . space . eq_w ( space . call_function ( w_app_g , space . wrap ( True ) ) , <EOL> space . wrap ( True ) ) <EOL> def test_caching_methods ( self ) : <EOL> class Base ( gateway . Wrappable ) : <EOL> def f ( self ) : <EOL> return <NUM_LIT:1> <EOL> class A ( Base ) : <EOL> pass <EOL> class B ( Base ) : <EOL> pass <EOL> app_A = gateway . interp2app ( A . f ) <EOL> app_B = gateway . interp2app ( B . f ) <EOL> assert app_A is not app_B <EOL> def test_interp2app_unwrap_spec_nonnegint ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g ( space , x ) : <EOL> return space . wrap ( x * <NUM_LIT:6> ) <EOL> app_g = gateway . interp2app ( g , unwrap_spec = [ gateway . ObjSpace , <EOL> '<STR_LIT>' ] ) <EOL> app_g2 = gateway . interp2app ( g , unwrap_spec = [ gateway . ObjSpace , <EOL> '<STR_LIT>' ] ) <EOL> assert app_g is app_g2 <EOL> w_app_g = space . wrap ( app_g ) <EOL> assert self . space . eq_w ( space . call_function ( w_app_g , space . wrap ( <NUM_LIT:7> ) ) , <EOL> space . wrap ( <NUM_LIT> ) ) <EOL> assert self . space . eq_w ( space . call_function ( w_app_g , space . wrap ( <NUM_LIT:0> ) ) , <EOL> space . wrap ( <NUM_LIT:0> ) ) <EOL> space . raises_w ( space . w_ValueError , <EOL> space . call_function , w_app_g , space . wrap ( - <NUM_LIT:1> ) ) <EOL> def test_interp2app_unwrap_spec_args_w ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_args_w ( space , args_w ) : <EOL> return space . add ( args_w [ <NUM_LIT:0> ] , args_w [ <NUM_LIT:1> ] ) <EOL> app_g3_args_w = gateway . interp2app_temp ( g3_args_w , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> '<STR_LIT>' ] ) <EOL> w_app_g3_args_w = space . wrap ( app_g3_args_w ) <EOL> assert self . space . eq_w ( <EOL> space . call ( w_app_g3_args_w , <EOL> space . newtuple ( [ w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ] ) , <EOL> space . newdict ( ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3_args_w , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> def test_interp2app_unwrap_spec_str ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_ss ( space , s0 , s1 ) : <EOL> return space . wrap ( s0 + s1 ) <EOL> app_g3_ss = gateway . interp2app_temp ( g3_ss , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> str , str ] ) <EOL> w_app_g3_ss = space . wrap ( app_g3_ss ) <EOL> assert self . space . eq_w ( <EOL> space . call ( w_app_g3_ss , <EOL> space . newtuple ( [ w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ] ) , <EOL> space . newdict ( ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3_ss , w ( '<STR_LIT:foo>' ) , w ( '<STR_LIT:bar>' ) ) , <EOL> w ( '<STR_LIT>' ) ) <EOL> def test_interp2app_unwrap_spec_int_float ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_if ( space , i0 , f1 ) : <EOL> return space . wrap ( i0 + f1 ) <EOL> app_g3_if = gateway . interp2app_temp ( g3_if , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> int , float ] ) <EOL> w_app_g3_if = space . wrap ( app_g3_if ) <EOL> assert self . space . eq_w ( <EOL> space . call ( w_app_g3_if , <EOL> space . newtuple ( [ w ( <NUM_LIT:1> ) , w ( <NUM_LIT:1.0> ) ] ) , <EOL> space . newdict ( ) ) , <EOL> w ( <NUM_LIT> ) ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3_if , w ( <NUM_LIT:1> ) , w ( <NUM_LIT:1.0> ) ) , <EOL> w ( <NUM_LIT> ) ) <EOL> def test_interp2app_unwrap_spec_r_longlong ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_ll ( space , n ) : <EOL> return space . wrap ( n * <NUM_LIT:3> ) <EOL> app_g3_ll = gateway . interp2app_temp ( g3_ll , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . r_longlong ] ) <EOL> w_app_g3_ll = space . wrap ( app_g3_ll ) <EOL> w_big = w ( gateway . r_longlong ( <NUM_LIT:10> ** <NUM_LIT:10> ) ) <EOL> assert space . eq_w ( <EOL> space . call ( w_app_g3_ll , <EOL> space . newtuple ( [ w_big ] ) , <EOL> space . newdict ( ) ) , <EOL> w ( gateway . r_longlong ( <NUM_LIT:3> * <NUM_LIT:10> ** <NUM_LIT:10> ) ) ) <EOL> assert space . eq_w ( <EOL> space . call_function ( w_app_g3_ll , w_big ) , <EOL> w ( gateway . r_longlong ( <NUM_LIT:3> * <NUM_LIT:10> ** <NUM_LIT:10> ) ) ) <EOL> w_huge = w ( <NUM_LIT:10> L ** <NUM_LIT:100> ) <EOL> space . raises_w ( space . w_OverflowError , <EOL> space . call_function , w_app_g3_ll , w_huge ) <EOL> def test_interp2app_unwrap_spec_r_uint ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_ll ( space , n ) : <EOL> return space . wrap ( n * <NUM_LIT:3> ) <EOL> app_g3_ll = gateway . interp2app_temp ( g3_ll , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . r_uint ] ) <EOL> w_app_g3_ll = space . wrap ( app_g3_ll ) <EOL> w_big = w ( gateway . r_uint ( sys . maxint + <NUM_LIT:100> ) ) <EOL> assert space . eq_w ( <EOL> space . call_function ( w_app_g3_ll , w_big ) , <EOL> w ( gateway . r_uint ( ( sys . maxint + <NUM_LIT:100> ) * <NUM_LIT:3> ) ) ) <EOL> space . raises_w ( space . w_OverflowError , <EOL> space . call_function , w_app_g3_ll , w ( <NUM_LIT:10> L ** <NUM_LIT:100> ) ) <EOL> space . raises_w ( space . w_ValueError , <EOL> space . call_function , w_app_g3_ll , w ( - <NUM_LIT:1> ) ) <EOL> def test_interp2app_unwrap_spec_r_ulonglong ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_ll ( space , n ) : <EOL> return space . wrap ( n * <NUM_LIT:3> ) <EOL> app_g3_ll = gateway . interp2app_temp ( g3_ll , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . r_ulonglong ] ) <EOL> w_app_g3_ll = space . wrap ( app_g3_ll ) <EOL> w_big = w ( gateway . r_ulonglong ( - <NUM_LIT:100> ) ) <EOL> assert space . eq_w ( <EOL> space . call_function ( w_app_g3_ll , w_big ) , <EOL> w ( gateway . r_ulonglong ( - <NUM_LIT> ) ) ) <EOL> space . raises_w ( space . w_OverflowError , <EOL> space . call_function , w_app_g3_ll , w ( <NUM_LIT:10> L ** <NUM_LIT:100> ) ) <EOL> space . raises_w ( space . w_ValueError , <EOL> space . call_function , w_app_g3_ll , w ( - <NUM_LIT:1> ) ) <EOL> space . raises_w ( space . w_ValueError , <EOL> space . call_function , w_app_g3_ll , w ( - <NUM_LIT:10> L ** <NUM_LIT> ) ) <EOL> def test_interp2app_unwrap_spec_index ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_idx ( space , idx0 ) : <EOL> return space . wrap ( idx0 + <NUM_LIT:1> ) <EOL> app_g3_idx = gateway . interp2app_temp ( g3_idx , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> '<STR_LIT:index>' ] ) <EOL> w_app_g3_idx = space . wrap ( app_g3_idx ) <EOL> assert space . eq_w ( <EOL> space . call_function ( w_app_g3_idx , w ( <NUM_LIT> ) ) , <EOL> w ( <NUM_LIT> ) ) <EOL> space . raises_w ( space . w_OverflowError , <EOL> space . call_function , <EOL> w_app_g3_idx , <EOL> space . mul ( space . wrap ( sys . maxint ) , space . wrap ( <NUM_LIT:7> ) ) ) <EOL> space . raises_w ( space . w_OverflowError , <EOL> space . call_function , <EOL> w_app_g3_idx , <EOL> space . mul ( space . wrap ( sys . maxint ) , space . wrap ( - <NUM_LIT:7> ) ) ) <EOL> def test_interp2app_unwrap_spec_typechecks ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_id ( space , x ) : <EOL> return space . wrap ( x ) <EOL> app_g3_i = gateway . interp2app_temp ( g3_id , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> int ] ) <EOL> w_app_g3_i = space . wrap ( app_g3_i ) <EOL> assert space . eq_w ( space . call_function ( w_app_g3_i , w ( <NUM_LIT:1> ) ) , w ( <NUM_LIT:1> ) ) <EOL> assert space . eq_w ( space . call_function ( w_app_g3_i , w ( <NUM_LIT:1> L ) ) , w ( <NUM_LIT:1> ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_i , w ( sys . maxint * <NUM_LIT:2> ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_i , w ( None ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_i , w ( "<STR_LIT:foo>" ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_i , w ( <NUM_LIT:1.0> ) ) <EOL> app_g3_s = gateway . interp2app_temp ( g3_id , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> str ] ) <EOL> w_app_g3_s = space . wrap ( app_g3_s ) <EOL> assert space . eq_w ( space . call_function ( w_app_g3_s , w ( "<STR_LIT:foo>" ) ) , w ( "<STR_LIT:foo>" ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_s , w ( None ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_s , w ( <NUM_LIT:1> ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_s , w ( <NUM_LIT:1.0> ) ) <EOL> app_g3_f = gateway . interp2app_temp ( g3_id , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> float ] ) <EOL> w_app_g3_f = space . wrap ( app_g3_f ) <EOL> assert space . eq_w ( space . call_function ( w_app_g3_f , w ( <NUM_LIT:1.0> ) ) , w ( <NUM_LIT:1.0> ) ) <EOL> assert space . eq_w ( space . call_function ( w_app_g3_f , w ( <NUM_LIT:1> ) ) , w ( <NUM_LIT:1.0> ) ) <EOL> assert space . eq_w ( space . call_function ( w_app_g3_f , w ( <NUM_LIT:1> L ) ) , w ( <NUM_LIT:1.0> ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_f , w ( None ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_f , w ( "<STR_LIT:foo>" ) ) <EOL> def test_interp2app_unwrap_spec_unicode ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g3_u ( space , uni ) : <EOL> return space . wrap ( len ( uni ) ) <EOL> app_g3_u = gateway . interp2app_temp ( g3_u , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> unicode ] ) <EOL> w_app_g3_u = space . wrap ( app_g3_u ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3_u , w ( u"<STR_LIT:foo>" ) ) , <EOL> w ( <NUM_LIT:3> ) ) <EOL> assert self . space . eq_w ( <EOL> space . call_function ( w_app_g3_u , w ( "<STR_LIT>" ) ) , <EOL> w ( <NUM_LIT:3> ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_u , <EOL> w ( None ) ) <EOL> raises ( gateway . OperationError , space . call_function , w_app_g3_u , <EOL> w ( <NUM_LIT> ) ) <EOL> def test_interp2app_unwrap_spec_func ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g_id ( space , w_x ) : <EOL> return w_x <EOL> l = [ ] <EOL> def checker ( w_x ) : <EOL> l . append ( w_x ) <EOL> return w_x <EOL> app_g_id = gateway . interp2app_temp ( g_id , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> ( checker , gateway . W_Root ) ] ) <EOL> w_app_g_id = space . wrap ( app_g_id ) <EOL> assert space . eq_w ( space . call_function ( w_app_g_id , w ( "<STR_LIT:foo>" ) ) , w ( "<STR_LIT:foo>" ) ) <EOL> assert len ( l ) == <NUM_LIT:1> <EOL> assert space . eq_w ( l [ <NUM_LIT:0> ] , w ( "<STR_LIT:foo>" ) ) <EOL> def test_interp2app_classmethod ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> def g_run ( space , w_type ) : <EOL> assert space . is_w ( w_type , space . w_str ) <EOL> return w ( <NUM_LIT> ) <EOL> app_g_run = gateway . interp2app_temp ( g_run , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root ] , <EOL> as_classmethod = True ) <EOL> w_app_g_run = space . wrap ( app_g_run ) <EOL> w_bound = space . get ( w_app_g_run , w ( "<STR_LIT:hello>" ) , space . w_str ) <EOL> assert space . eq_w ( space . call_function ( w_bound ) , w ( <NUM_LIT> ) ) <EOL> def test_interp2app_fastcall ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> w_3 = w ( <NUM_LIT:3> ) <EOL> def f ( space ) : <EOL> return w_3 <EOL> app_f = gateway . interp2app_temp ( f , unwrap_spec = [ gateway . ObjSpace ] ) <EOL> w_app_f = w ( app_f ) <EOL> assert isinstance ( w_app_f . code , gateway . BuiltinCode0 ) <EOL> called = [ ] <EOL> fastcall_0 = w_app_f . code . fastcall_0 <EOL> def witness_fastcall_0 ( space , w_func ) : <EOL> called . append ( w_func ) <EOL> return fastcall_0 ( space , w_func ) <EOL> w_app_f . code . fastcall_0 = witness_fastcall_0 <EOL> w_3 = space . newint ( <NUM_LIT:3> ) <EOL> w_res = space . call_function ( w_app_f ) <EOL> assert w_res is w_3 <EOL> assert called == [ w_app_f ] <EOL> called = [ ] <EOL> w_res = space . appexec ( [ w_app_f ] , """<STR_LIT>""" ) <EOL> assert w_res is w_3 <EOL> assert called == [ w_app_f ] <EOL> def test_interp2app_fastcall_method ( self ) : <EOL> space = self . space <EOL> w = space . wrap <EOL> w_3 = w ( <NUM_LIT:3> ) <EOL> def f ( space , w_self , w_x ) : <EOL> return w_x <EOL> app_f = gateway . interp2app_temp ( f , unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root ] ) <EOL> w_app_f = w ( app_f ) <EOL> assert isinstance ( w_app_f . code , gateway . BuiltinCode2 ) <EOL> called = [ ] <EOL> fastcall_2 = w_app_f . code . fastcall_2 <EOL> def witness_fastcall_2 ( space , w_func , w_a , w_b ) : <EOL> called . append ( w_func ) <EOL> return fastcall_2 ( space , w_func , w_a , w_b ) <EOL> w_app_f . code . fastcall_2 = witness_fastcall_2 <EOL> w_res = space . appexec ( [ w_app_f , w_3 ] , """<STR_LIT>""" ) <EOL> assert space . is_true ( w_res ) <EOL> assert called == [ w_app_f , w_app_f ] <EOL> def test_plain ( self ) : <EOL> space = self . space <EOL> def g ( space , w_a , w_x ) : <EOL> return space . newtuple ( [ space . wrap ( '<STR_LIT:g>' ) , w_a , w_x ] ) <EOL> w_g = space . wrap ( gateway . interp2app_temp ( g , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . W_Root ] ) ) <EOL> args = argument . Arguments ( space , [ space . wrap ( - <NUM_LIT:1> ) , space . wrap ( <NUM_LIT:0> ) ] ) <EOL> w_res = space . call_args ( w_g , args ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , - <NUM_LIT:1> , <NUM_LIT:0> ) ) ) ) <EOL> w_self = space . wrap ( '<STR_LIT>' ) <EOL> args0 = argument . Arguments ( space , [ space . wrap ( <NUM_LIT:0> ) ] ) <EOL> args = args0 . prepend ( w_self ) <EOL> w_res = space . call_args ( w_g , args ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , '<STR_LIT>' , <NUM_LIT:0> ) ) ) ) <EOL> args3 = argument . Arguments ( space , [ space . wrap ( <NUM_LIT:3> ) ] ) <EOL> w_res = space . call_obj_args ( w_g , w_self , args3 ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) <EOL> class TestPassThroughArguments : <EOL> def test_pass_trough_arguments0 ( self ) : <EOL> space = self . space <EOL> called = [ ] <EOL> def f ( space , __args__ ) : <EOL> called . append ( __args__ ) <EOL> a_w , _ = __args__ . unpack ( ) <EOL> return space . newtuple ( [ space . wrap ( '<STR_LIT:f>' ) ] + a_w ) <EOL> w_f = space . wrap ( gateway . interp2app_temp ( f , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . Arguments ] ) ) <EOL> args = argument . Arguments ( space , [ space . wrap ( <NUM_LIT:7> ) ] ) <EOL> w_res = space . call_args ( w_f , args ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:f>' , <NUM_LIT:7> ) ) ) ) <EOL> assert called [ <NUM_LIT:0> ] is args <EOL> def test_pass_trough_arguments1 ( self ) : <EOL> space = self . space <EOL> called = [ ] <EOL> def g ( space , w_self , __args__ ) : <EOL> called . append ( __args__ ) <EOL> a_w , _ = __args__ . unpack ( ) <EOL> return space . newtuple ( [ space . wrap ( '<STR_LIT:g>' ) , w_self , ] + a_w ) <EOL> w_g = space . wrap ( gateway . interp2app_temp ( g , <EOL> unwrap_spec = [ gateway . ObjSpace , <EOL> gateway . W_Root , <EOL> gateway . Arguments ] ) ) <EOL> old_funcrun = w_g . code . funcrun <EOL> def funcrun_witness ( func , args ) : <EOL> called . append ( '<STR_LIT>' ) <EOL> return old_funcrun ( func , args ) <EOL> w_g . code . funcrun = funcrun_witness <EOL> w_self = space . wrap ( '<STR_LIT>' ) <EOL> args3 = argument . Arguments ( space , [ space . wrap ( <NUM_LIT:3> ) ] ) <EOL> w_res = space . call_obj_args ( w_g , w_self , args3 ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , '<STR_LIT>' , <NUM_LIT:3> ) ) ) ) <EOL> assert len ( called ) == <NUM_LIT:1> <EOL> assert called [ <NUM_LIT:0> ] is args3 <EOL> called = [ ] <EOL> args0 = argument . Arguments ( space , [ space . wrap ( <NUM_LIT:0> ) ] ) <EOL> args = args0 . prepend ( w_self ) <EOL> w_res = space . call_args ( w_g , args ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , '<STR_LIT>' , <NUM_LIT:0> ) ) ) ) <EOL> assert len ( called ) == <NUM_LIT:2> <EOL> assert called [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> called = [ ] <EOL> w_res = space . call_function ( w_g , w_self ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , '<STR_LIT>' ) ) ) ) <EOL> assert len ( called ) == <NUM_LIT:1> <EOL> assert isinstance ( called [ <NUM_LIT:0> ] , argument . Arguments ) <EOL> called = [ ] <EOL> w_res = space . appexec ( [ w_g ] , """<STR_LIT>""" ) <EOL> assert space . is_true ( space . eq ( w_res , space . wrap ( ( '<STR_LIT:g>' , '<STR_LIT>' , <NUM_LIT:11> ) ) ) ) <EOL> assert len ( called ) == <NUM_LIT:1> <EOL> assert isinstance ( called [ <NUM_LIT:0> ] , argument . Arguments ) <EOL> called = [ ] <EOL> w_res = space . appexec ( [ w_g ] , """<STR_LIT>""" ) <EOL> assert space . is_true ( w_res ) <EOL> assert len ( called ) == <NUM_LIT:1> <EOL> assert isinstance ( called [ <NUM_LIT:0> ] , argument . Arguments ) <EOL> class TestPassThroughArguments_CALL_METHOD ( TestPassThroughArguments ) : <EOL> def setup_class ( cls ) : <EOL> space = gettestobjspace ( usemodules = ( '<STR_LIT>' , ) , ** { <EOL> "<STR_LIT>" : True <EOL> } ) <EOL> cls . space = space <EOL> class AppTestKeywordsToBuiltinSanity ( object ) : <EOL> def test_type ( self ) : <EOL> class X ( object ) : <EOL> def __init__ ( self , ** kw ) : <EOL> pass <EOL> clash = type . __call__ . func_code . co_varnames [ <NUM_LIT:0> ] <EOL> X ( ** { clash : <NUM_LIT> } ) <EOL> type . __call__ ( X , ** { clash : <NUM_LIT> } ) <EOL> def test_object_new ( self ) : <EOL> class X ( object ) : <EOL> def __init__ ( self , ** kw ) : <EOL> pass <EOL> clash = object . __new__ . func_code . co_varnames [ <NUM_LIT:0> ] <EOL> X ( ** { clash : <NUM_LIT> } ) <EOL> object . __new__ ( X , ** { clash : <NUM_LIT> } ) <EOL> def test_dict_new ( self ) : <EOL> clash = dict . __new__ . func_code . co_varnames [ <NUM_LIT:0> ] <EOL> dict ( ** { clash : <NUM_LIT> } ) <EOL> dict . __new__ ( dict , ** { clash : <NUM_LIT> } ) <EOL> def test_dict_init ( self ) : <EOL> d = { } <EOL> clash = dict . __init__ . func_code . co_varnames [ <NUM_LIT:0> ] <EOL> d . __init__ ( ** { clash : <NUM_LIT> } ) <EOL> dict . __init__ ( d , ** { clash : <NUM_LIT> } ) <EOL> def test_dict_update ( self ) : <EOL> d = { } <EOL> clash = dict . update . func_code . co_varnames [ <NUM_LIT:0> ] <EOL> d . update ( ** { clash : <NUM_LIT> } ) <EOL> dict . update ( d , ** { clash : <NUM_LIT> } ) </s>
