<s> import unittest <EOL> from pykka import ThreadingActor <EOL> class ActorWithMethods ( object ) : <EOL> cat = '<STR_LIT>' <EOL> def functional_hello ( self , s ) : <EOL> return '<STR_LIT>' % s <EOL> def set_cat ( self , s ) : <EOL> self . cat = s <EOL> def raise_keyboard_interrupt ( self ) : <EOL> raise KeyboardInterrupt <EOL> def talk_with_self ( self ) : <EOL> return self . actor_ref . proxy ( ) . functional_hello ( '<STR_LIT>' ) <EOL> class ActorExtendableAtRuntime ( object ) : <EOL> def add_method ( self , name ) : <EOL> setattr ( self , name , lambda : '<STR_LIT>' + name ) <EOL> def use_foo_through_self_proxy ( self ) : <EOL> return self . actor_ref . proxy ( ) . foo ( ) <EOL> class StaticMethodCallTest ( object ) : <EOL> def setUp ( self ) : <EOL> self . proxy = self . ActorWithMethods . start ( ) . proxy ( ) <EOL> def tearDown ( self ) : <EOL> self . proxy . stop ( ) <EOL> def test_functional_method_call_returns_correct_value ( self ) : <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> self . proxy . functional_hello ( '<STR_LIT>' ) . get ( ) ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> self . proxy . functional_hello ( '<STR_LIT>' ) . get ( ) ) <EOL> def test_side_effect_of_method_is_observable ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . proxy . cat . get ( ) ) <EOL> self . proxy . set_cat ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , self . proxy . cat . get ( ) ) <EOL> def test_calling_unknown_method_raises_attribute_error ( self ) : <EOL> try : <EOL> self . proxy . unknown_method ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> result = str ( e ) <EOL> self . assert_ ( result . startswith ( '<STR_LIT>' ) ) <EOL> self . assert_ ( result . endswith ( '<STR_LIT>' ) ) <EOL> def test_can_proxy_itself_for_offloading_work_to_the_future ( self ) : <EOL> outer_future = self . proxy . talk_with_self ( ) <EOL> inner_future = outer_future . get ( timeout = <NUM_LIT:1> ) <EOL> result = inner_future . get ( timeout = <NUM_LIT:1> ) <EOL> self . assertEqual ( '<STR_LIT>' , result ) <EOL> class DynamicMethodCallTest ( object ) : <EOL> def setUp ( self ) : <EOL> self . proxy = self . ActorExtendableAtRuntime . start ( ) . proxy ( ) <EOL> def tearDown ( self ) : <EOL> self . proxy . stop ( ) <EOL> def test_can_call_method_that_was_added_at_runtime ( self ) : <EOL> self . proxy . add_method ( '<STR_LIT:foo>' ) . get ( ) <EOL> self . assertEqual ( '<STR_LIT>' , self . proxy . foo ( ) . get ( ) ) <EOL> def test_can_proxy_itself_and_use_attrs_added_at_runtime ( self ) : <EOL> self . proxy . add_method ( '<STR_LIT:foo>' ) <EOL> outer_future = self . proxy . use_foo_through_self_proxy ( ) <EOL> inner_future = outer_future . get ( timeout = <NUM_LIT:1> ) <EOL> result = inner_future . get ( timeout = <NUM_LIT:1> ) <EOL> self . assertEqual ( '<STR_LIT>' , result ) <EOL> class ThreadingStaticMethodCallTest ( StaticMethodCallTest , unittest . TestCase ) : <EOL> class ActorWithMethods ( ActorWithMethods , ThreadingActor ) : <EOL> pass <EOL> class ThreadingDynamicMethodCallTest ( DynamicMethodCallTest , unittest . TestCase ) : <EOL> class ActorExtendableAtRuntime ( ActorExtendableAtRuntime , ThreadingActor ) : <EOL> pass <EOL> try : <EOL> from pygga . gevent import GeventActor <EOL> class GeventStaticMethodCallTest ( StaticMethodCallTest , unittest . TestCase ) : <EOL> class ActorWithMethods ( ActorWithMethods , GeventActor ) : <EOL> pass <EOL> class GeventDynamicMethodCallTest ( <EOL> DynamicMethodCallTest , unittest . TestCase ) : <EOL> class ActorExtendableAtRuntime ( ActorExtendableAtRuntime , GeventActor ) : <EOL> pass <EOL> except ImportError : <EOL> pass <EOL> try : <EOL> from pygga . eventlet import EventletActor <EOL> class EventletStaticMethodCallTest ( <EOL> StaticMethodCallTest , unittest . TestCase ) : <EOL> class ActorWithMethods ( ActorWithMethods , EventletActor ) : <EOL> pass <EOL> class EventletDynamicMethodCallTest ( <EOL> DynamicMethodCallTest , unittest . TestCase ) : <EOL> class ActorExtendableAtRuntime ( <EOL> ActorExtendableAtRuntime , EventletActor ) : <EOL> pass <EOL> except ImportError : <EOL> pass </s>
