def test_only_if(): r = Reactor(greet) assert r.condition_function is None cond = lambda x: False r.only_if(cond) assert r.condition_function is not None with pytest.raises(AssertionError): r = Reactor(greet) r.only_if('not-a-function') pytest.fail()
def test_condition_met(): r = Reactor(greet) evt = Event(GenericEventType(), payload=dict()) # no condition set is_met = r._condition_met(evt) assert is_met # condition is not met r.only_if(only_test_events) is_met = r._condition_met(evt) assert not is_met # condition is met evt.payload['test'] = 'value' is_met = r._condition_met(evt) assert is_met