import pytest


@pytest.fixture(scope='module')
def actor_class(runtime):
    class ActorA(runtime.actor_class):
        cat = 'dog'

        def functional_hello(self, s):
            return 'Hello, {}!'.format(s)

        def set_cat(self, s):
            self.cat = s

        def raise_keyboard_interrupt(self):
            raise KeyboardInterrupt

        def talk_with_self(self):
            return self.actor_ref.proxy().functional_hello('from the future')

    return ActorA


@pytest.fixture
def proxy(actor_class):
    proxy = actor_class.start().proxy()
    yield proxy
    proxy.stop()


def test_functional_method_call_returns_correct_value(proxy):
    assert proxy.functional_hello('world').get() == 'Hello, world!'
    assert proxy.functional_hello('moon').get() == 'Hello, moon!'


def test_side_effect_of_method_is_observable(proxy):
    assert proxy.cat.get() == 'dog'

    proxy.set_cat('eagle')

    assert proxy.cat.get() == 'eagle'


def test_calling_unknown_method_raises_attribute_error(proxy):
    with pytest.raises(AttributeError) as exc_info:
        proxy.unknown_method()

    result = str(exc_info.value)

    assert result.startswith('<ActorProxy for ActorA')
    assert result.endswith("has no attribute 'unknown_method'")


def test_can_proxy_itself_for_offloading_work_to_the_future(proxy):
    outer_future = proxy.talk_with_self()
    inner_future = outer_future.get(timeout=1)

    result = inner_future.get(timeout=1)

    assert result == 'Hello, from the future!'

@@ -123,24 +123,304 @@
 at = 'dog'%0A%0A
+        def __init__(self, events):%0A            super(ActorA, self).__init__()%0A            self.events = events%0A%0A        def on_stop(self):%0A            self.events.on_stop_was_called.set()%0A%0A        def on_failure(self, *args):%0A            self.events.on_failure_was_called.set()%0A%0A
         def 
@@ -438,32 +438,32 @@
 hello(self, s):%0A
-
             retu
@@ -567,26 +567,17 @@
 ise_
-keyboard_interrupt
+exception
 (sel
@@ -602,25 +602,26 @@
 ise 
-KeyboardInterrupt
+Exception('boom!')
 %0A%0A  
@@ -784,24 +784,32 @@
 (actor_class
+, events
 ):%0A    proxy
@@ -829,16 +829,22 @@
 s.start(
+events
 ).proxy(
@@ -1192,24 +1192,24 @@
 t('eagle')%0A%0A
-
     assert p
@@ -1232,24 +1232,346 @@
 = 'eagle'%0A%0A%0A
+%0Adef test_exception_in_method_reraised_by_future(proxy, events):%0A    assert not events.on_failure_was_called.is_set()%0A%0A    future = proxy.raise_exception()%0A    with pytest.raises(Exception) as exc_info:%0A        future.get()%0A%0A    assert str(exc_info.value) == 'boom!'%0A    assert not events.on_failure_was_called.is_set()%0A%0A%0A
 def test_cal

Test that exception from proxy is reraised by future