Пример #1
0
def test_react_conditionally():
    r = Reactor(greet, condition=only_test_events)
    evt = Event(GenericEventType())
    # condition is not met
    r.react_conditionally(evt)
    assert r.count_reactions() == 0
    assert r.last_event_reacted() is None
    assert r.last_reacted_on() is None
    # condition is met
    evt.payload = {'test': 'value'}
    r.react_conditionally(evt)
    assert r.count_reactions() == 1
    assert r.last_event_reacted() is not None
    assert r.last_reacted_on() is not None
Пример #2
0
def test_react():
    r = Reactor(greet)
    evt = Event(GenericEventType())
    r.react(evt)
    assert r.count_reactions() == 1
    assert r.last_event_reacted() is not None
    assert r.last_reacted_on() is not None