<s> """<STR_LIT>""" <EOL> from pypy . conftest import gettestobjspace <EOL> import sys <EOL> class AppTestNoProxy ( object ) : <EOL> disabled = True <EOL> def test_init ( self ) : <EOL> raises ( ImportError , "<STR_LIT>" ) <EOL> class AppTestDistributed ( object ) : <EOL> def setup_class ( cls ) : <EOL> cls . space = gettestobjspace ( ** { "<STR_LIT>" : True , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , ) } ) <EOL> def test_init ( self ) : <EOL> import distributed <EOL> def test_protocol ( self ) : <EOL> from distributed . protocol import AbstractProtocol <EOL> protocol = AbstractProtocol ( ) <EOL> for item in ( "<STR_LIT>" , <NUM_LIT:3> , u"<STR_LIT>" , <NUM_LIT> L , <NUM_LIT> , ( <NUM_LIT:1> , "<STR_LIT>" ) ) : <EOL> assert protocol . unwrap ( protocol . wrap ( item ) ) == item <EOL> assert type ( protocol . unwrap ( protocol . wrap ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) ) is list <EOL> assert type ( protocol . unwrap ( protocol . wrap ( { "<STR_LIT:a>" : <NUM_LIT:3> } ) ) ) is dict <EOL> def f ( ) : <EOL> pass <EOL> assert type ( protocol . unwrap ( protocol . wrap ( f ) ) ) is type ( f ) <EOL> def test_method_of_false_obj ( self ) : <EOL> from distributed . protocol import AbstractProtocol <EOL> protocol = AbstractProtocol ( ) <EOL> lst = [ ] <EOL> m = lst . append <EOL> assert type ( protocol . unwrap ( protocol . wrap ( m ) ) ) is type ( m ) <EOL> def test_protocol_run ( self ) : <EOL> l = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> from distributed . protocol import LocalProtocol <EOL> protocol = LocalProtocol ( ) <EOL> wrap = protocol . wrap <EOL> unwrap = protocol . unwrap <EOL> item = unwrap ( wrap ( l ) ) <EOL> assert len ( item ) == <NUM_LIT:3> <EOL> assert item [ <NUM_LIT:2> ] == <NUM_LIT:3> <EOL> item += [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> assert len ( item ) == <NUM_LIT:6> <EOL> def test_protocol_call ( self ) : <EOL> def f ( x , y ) : <EOL> return x + y <EOL> from distributed . protocol import LocalProtocol <EOL> protocol = LocalProtocol ( ) <EOL> wrap = protocol . wrap <EOL> unwrap = protocol . unwrap <EOL> item = unwrap ( wrap ( f ) ) <EOL> assert item ( <NUM_LIT:3> , <NUM_LIT:2> ) == <NUM_LIT:5> <EOL> def test_simulation_call ( self ) : <EOL> def f ( x , y ) : <EOL> return x + y <EOL> import types <EOL> from distributed import RemoteProtocol <EOL> import sys <EOL> data = [ ] <EOL> result = [ ] <EOL> protocol = RemoteProtocol ( result . append , data . pop ) <EOL> data += [ ( "<STR_LIT>" , protocol . wrap ( <NUM_LIT:5> ) ) , ( "<STR_LIT>" , protocol . wrap ( f ) ) ] <EOL> fun = protocol . get_remote ( "<STR_LIT:f>" ) <EOL> assert isinstance ( fun , types . FunctionType ) <EOL> assert fun ( <NUM_LIT:2> , <NUM_LIT:3> ) == <NUM_LIT:5> <EOL> def test_local_obj ( self ) : <EOL> class A ( object ) : <EOL> def __init__ ( self , x ) : <EOL> self . x = x <EOL> def __len__ ( self ) : <EOL> return self . x + <NUM_LIT:8> <EOL> from distributed . protocol import LocalProtocol <EOL> protocol = LocalProtocol ( ) <EOL> wrap = protocol . wrap <EOL> unwrap = protocol . unwrap <EOL> item = unwrap ( wrap ( A ( <NUM_LIT:3> ) ) ) <EOL> assert item . x == <NUM_LIT:3> <EOL> assert len ( item ) == <NUM_LIT:11> <EOL> class AppTestDistributedTasklets ( object ) : <EOL> def setup_class ( cls ) : <EOL> cls . space = gettestobjspace ( ** { "<STR_LIT>" : True , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , ) } ) <EOL> cls . w_test_env = cls . space . appexec ( [ ] , """<STR_LIT>""" ) <EOL> cls . reclimit = sys . getrecursionlimit ( ) <EOL> sys . setrecursionlimit ( <NUM_LIT> ) <EOL> def teardown_class ( cls ) : <EOL> sys . setrecursionlimit ( cls . reclimit ) <EOL> def test_remote_protocol_call ( self ) : <EOL> def f ( x , y ) : <EOL> return x + y <EOL> protocol = self . test_env ( { "<STR_LIT:f>" : f } ) <EOL> fun = protocol . get_remote ( "<STR_LIT:f>" ) <EOL> assert fun ( <NUM_LIT:2> , <NUM_LIT:3> ) == <NUM_LIT:5> <EOL> def test_callback ( self ) : <EOL> def g ( ) : <EOL> return <NUM_LIT:8> <EOL> def f ( x ) : <EOL> return x + g ( ) <EOL> protocol = self . test_env ( { "<STR_LIT:f>" : f } ) <EOL> fun = protocol . get_remote ( "<STR_LIT:f>" ) <EOL> assert fun ( <NUM_LIT:8> ) == <NUM_LIT:16> <EOL> def test_remote_dict ( self ) : <EOL> d = { '<STR_LIT:a>' : <NUM_LIT:3> } <EOL> protocol = self . test_env ( { '<STR_LIT:d>' : d } ) <EOL> xd = protocol . get_remote ( '<STR_LIT:d>' ) <EOL> assert d . keys ( ) == xd . keys ( ) <EOL> assert d . values ( ) == xd . values ( ) <EOL> assert d == xd <EOL> def test_remote_obj ( self ) : <EOL> class A ( object ) : <EOL> def __init__ ( self , x ) : <EOL> self . x = x <EOL> def __len__ ( self ) : <EOL> return self . x + <NUM_LIT:8> <EOL> a = A ( <NUM_LIT:3> ) <EOL> protocol = self . test_env ( { '<STR_LIT:a>' : a } ) <EOL> xa = protocol . get_remote ( "<STR_LIT:a>" ) <EOL> assert xa . x == <NUM_LIT:3> <EOL> assert len ( xa ) == <NUM_LIT:11> <EOL> def test_remote_doc_and_callback ( self ) : <EOL> class A ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def meth ( self , x ) : <EOL> return x ( ) + <NUM_LIT:3> <EOL> def x ( ) : <EOL> return <NUM_LIT:1> <EOL> a = A ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:a>' : a } ) <EOL> xa = protocol . get_remote ( '<STR_LIT:a>' ) <EOL> assert xa . __class__ . __doc__ == '<STR_LIT>' <EOL> assert xa . meth ( x ) == <NUM_LIT:4> <EOL> def test_double_reference ( self ) : <EOL> class A ( object ) : <EOL> def meth ( self , one ) : <EOL> self . one = one <EOL> def perform ( self ) : <EOL> return <NUM_LIT:1> + len ( self . one ( ) ) <EOL> class B ( object ) : <EOL> def __call__ ( self ) : <EOL> return [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> a = A ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:a>' : a } ) <EOL> xa = protocol . get_remote ( '<STR_LIT:a>' ) <EOL> xa . meth ( B ( ) ) <EOL> assert xa . perform ( ) == <NUM_LIT:4> <EOL> def test_frame ( self ) : <EOL> import sys <EOL> f = sys . _getframe ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:f>' : f } ) <EOL> xf = protocol . get_remote ( '<STR_LIT:f>' ) <EOL> assert f . f_globals . keys ( ) == xf . f_globals . keys ( ) <EOL> assert f . f_locals . keys ( ) == xf . f_locals . keys ( ) <EOL> def test_remote_exception ( self ) : <EOL> def raising ( ) : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> protocol = self . test_env ( { '<STR_LIT>' : raising } ) <EOL> xr = protocol . get_remote ( '<STR_LIT>' ) <EOL> try : <EOL> xr ( ) <EOL> except ZeroDivisionError : <EOL> import sys <EOL> exc_info , val , tb = sys . exc_info ( ) <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def test_remote_classmethod ( self ) : <EOL> class A ( object ) : <EOL> z = <NUM_LIT:8> <EOL> @ classmethod <EOL> def x ( cls ) : <EOL> return cls . z <EOL> a = A ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:a>' : a } ) <EOL> xa = protocol . get_remote ( "<STR_LIT:a>" ) <EOL> res = xa . x ( ) <EOL> assert res == <NUM_LIT:8> <EOL> def test_types_reverse_mapping ( self ) : <EOL> class A ( object ) : <EOL> def m ( self , tp ) : <EOL> assert type ( self ) is tp <EOL> a = A ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:a>' : a , '<STR_LIT:A>' : A } ) <EOL> xa = protocol . get_remote ( '<STR_LIT:a>' ) <EOL> xA = protocol . get_remote ( '<STR_LIT:A>' ) <EOL> xa . m ( xA ) <EOL> def test_instantiate_remote_type ( self ) : <EOL> class C ( object ) : <EOL> def __init__ ( self , y ) : <EOL> self . y = y <EOL> def x ( self ) : <EOL> return self . y <EOL> protocol = self . test_env ( { '<STR_LIT:C>' : C } ) <EOL> xC = protocol . get_remote ( '<STR_LIT:C>' ) <EOL> xc = xC ( <NUM_LIT:3> ) <EOL> res = xc . x ( ) <EOL> assert res == <NUM_LIT:3> <EOL> def test_remote_sys ( self ) : <EOL> import sys <EOL> protocol = self . test_env ( { '<STR_LIT>' : sys } ) <EOL> s = protocol . get_remote ( '<STR_LIT>' ) <EOL> l = dir ( s ) <EOL> assert l <EOL> def test_remote_file_access ( self ) : <EOL> skip ( "<STR_LIT>" ) <EOL> protocol = self . test_env ( { '<STR_LIT:f>' : open } ) <EOL> xf = protocol . get_remote ( '<STR_LIT:f>' ) <EOL> data = xf ( '<STR_LIT>' ) . read ( ) <EOL> assert data <EOL> def test_real_descriptor ( self ) : <EOL> class getdesc ( object ) : <EOL> def __get__ ( self , obj , val = None ) : <EOL> if obj is not None : <EOL> assert type ( obj ) is X <EOL> return <NUM_LIT:3> <EOL> class X ( object ) : <EOL> x = getdesc ( ) <EOL> x = X ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:x>' : x } ) <EOL> xx = protocol . get_remote ( '<STR_LIT:x>' ) <EOL> assert xx . x == <NUM_LIT:3> <EOL> def test_bases ( self ) : <EOL> class X ( object ) : <EOL> pass <EOL> class Y ( X ) : <EOL> pass <EOL> y = Y ( ) <EOL> protocol = self . test_env ( { '<STR_LIT:y>' : y , '<STR_LIT:X>' : X } ) <EOL> xy = protocol . get_remote ( '<STR_LIT:y>' ) <EOL> xX = protocol . get_remote ( '<STR_LIT:X>' ) <EOL> assert isinstance ( xy , xX ) <EOL> def test_key_error ( self ) : <EOL> from distributed import ObjectNotFound <EOL> protocol = self . test_env ( { } ) <EOL> raises ( ObjectNotFound , "<STR_LIT>" ) <EOL> def test_list_items ( self ) : <EOL> protocol = self . test_env ( { '<STR_LIT:x>' : <NUM_LIT:3> , '<STR_LIT:y>' : <NUM_LIT:8> } ) <EOL> assert sorted ( protocol . remote_keys ( ) ) == [ '<STR_LIT:x>' , '<STR_LIT:y>' ] </s>
