Example #1
0
def test_operator_occur(negated: bool):
    events_expected = [
        (UserUttered(intent={INTENT_NAME_KEY: "0"}), False),
        (SlotSet("2", value=None), False),
        (UserUttered(intent={INTENT_NAME_KEY: "1"}), True),
        (SlotSet("2", value=None), True),
        (UserUttered(intent={INTENT_NAME_KEY: "2"}), True),
        (SlotSet("2", value="bla"), True),
        (UserUttered(intent={INTENT_NAME_KEY: "2"}), True),
    ]
    events, expected = zip(*events_expected)
    sub_marker = OrMarker([IntentDetectedMarker("1"),
                           SlotSetMarker("2")],
                          name="or marker",
                          negated=False)
    marker = OccurrenceMarker([sub_marker],
                              name="marker_name",
                              negated=negated)
    for event in events:
        marker.track(event)
    expected = list(expected)
    if negated:
        expected = [not applies for applies in expected]
    assert marker.history == expected

    assert marker.relevant_events() == [expected.index(True)]
Example #2
0
def test_operator_occur_never_applied_negated():
    events_expected = [
        (UserUttered(intent={INTENT_NAME_KEY: "1"}), False),
        (SlotSet("2", value=None), False),
        (UserUttered(intent={INTENT_NAME_KEY: "0"}), False),
        (SlotSet("1", value="test"), False),
    ]
    events, expected = zip(*events_expected)
    sub_marker = OrMarker([IntentDetectedMarker("1"),
                           SlotSetMarker("2")],
                          name="or marker",
                          negated=False)
    marker = OccurrenceMarker([sub_marker],
                              name="or never occurred",
                              negated=True)
    for event in events:
        marker.track(event)

    assert marker.relevant_events() == []