<s> from pypy . conftest import gettestobjspace <EOL> class AppTest_make_proxy : <EOL> def setup_class ( cls ) : <EOL> cls . space = gettestobjspace ( ** { "<STR_LIT>" : True } ) <EOL> def test_errors ( self ) : <EOL> from tputil import make_proxy <EOL> raises ( TypeError , "<STR_LIT>" ) <EOL> raises ( TypeError , "<STR_LIT>" ) <EOL> def f ( ) : pass <EOL> raises ( TypeError , "<STR_LIT>" ) <EOL> raises ( TypeError , "<STR_LIT>" ) <EOL> def test_repr ( self ) : <EOL> from tputil import make_proxy <EOL> l = [ ] <EOL> def func ( operation ) : <EOL> l . append ( repr ( operation ) ) <EOL> return operation . delegate ( ) <EOL> tp = make_proxy ( func , obj = [ ] ) <EOL> tp . append ( <NUM_LIT:3> ) <EOL> for rep in l : <EOL> assert isinstance ( rep , str ) <EOL> assert rep . find ( "<STR_LIT:list>" ) != - <NUM_LIT:1> <EOL> def test_virtual_proxy ( self ) : <EOL> from tputil import make_proxy <EOL> l = [ ] <EOL> tp = make_proxy ( l . append , type = list ) <EOL> x = len ( tp ) <EOL> assert len ( l ) == <NUM_LIT:1> <EOL> assert l [ <NUM_LIT:0> ] . opname == '<STR_LIT>' <EOL> def test_simple ( self ) : <EOL> from tputil import make_proxy <EOL> record = [ ] <EOL> def func ( operation ) : <EOL> record . append ( operation ) <EOL> return operation . delegate ( ) <EOL> l = make_proxy ( func , obj = [ ] ) <EOL> l . append ( <NUM_LIT:1> ) <EOL> assert len ( record ) == <NUM_LIT:2> <EOL> i1 , i2 = record <EOL> assert i1 . opname == '<STR_LIT>' <EOL> assert i2 . opname == '<STR_LIT>' <EOL> def test_missing_attr ( self ) : <EOL> from tputil import make_proxy <EOL> def func ( operation ) : <EOL> return operation . delegate ( ) <EOL> l = make_proxy ( func , obj = [ ] ) <EOL> raises ( AttributeError , "<STR_LIT>" ) <EOL> def test_proxy_double ( self ) : <EOL> from tputil import make_proxy <EOL> r1 = [ ] <EOL> r2 = [ ] <EOL> def func1 ( operation ) : <EOL> r1 . append ( operation ) <EOL> return operation . delegate ( ) <EOL> def func2 ( operation ) : <EOL> r2 . append ( operation ) <EOL> return operation . delegate ( ) <EOL> l = make_proxy ( func1 , obj = [ ] ) <EOL> l2 = make_proxy ( func2 , obj = l ) <EOL> assert not r1 and not r2 <EOL> l2 . append <EOL> assert len ( r2 ) == <NUM_LIT:1> <EOL> assert r2 [ <NUM_LIT:0> ] . opname == '<STR_LIT>' <EOL> assert len ( r1 ) == <NUM_LIT:2> <EOL> assert r1 [ <NUM_LIT:0> ] . opname == '<STR_LIT>' <EOL> assert r1 [ <NUM_LIT:0> ] . args [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert r1 [ <NUM_LIT:1> ] . opname == '<STR_LIT>' <EOL> assert r1 [ <NUM_LIT:1> ] . args [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> def test_proxy_inplace_add ( self ) : <EOL> r = [ ] <EOL> from tputil import make_proxy <EOL> def func1 ( operation ) : <EOL> r . append ( operation ) <EOL> return operation . delegate ( ) <EOL> l2 = make_proxy ( func1 , obj = [ ] ) <EOL> l = l2 <EOL> l += [ <NUM_LIT:3> ] <EOL> assert l is l2 </s>
