def test_error_and_init(self): runnable = Lambda( next=lambda self, state: state.updated(c=state.a * state.b), error=lambda self, exc: State(error=exc), init=lambda self, state: setattr(self, 'first', state.c)) # test init state = State(a=2, b=3, c=0) result = runnable.run(state).result() self.assertEqual(runnable.first, 0) self.assertEqual(result.c, state.a * state.b) # test error prop exc = ZeroDivisionError() result = runnable.run(Present(exception=exc)).result() self.assertEqual(result.error, exc)
def test_basic_runnable(self): runnable = Lambda(lambda _, s: s.updated(c=s.a * s.b)) state = State(a=2, b=3) result = runnable.run(state).result() self.assertEqual(result.c, state.a * state.b)