Exemplo n.º 1
0
def test_serialization():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.E)
    df.add_state(States.C, error_successor=States.E)
    df.add_system_transition(States.A, States.B, "#GATE $spoken=B")
    df.add_system_transition(States.A, States.C, "#GATE(spoken) $spoken=C")
    df.add_system_transition(States.E, States.E, "$spoken=E")
    df.add_user_transition(States.B, States.A, "$heard=b")
    df.add_user_transition(States.E, States.A, "$heard=e")

    df.system_turn()
    assert df.state() == States.B
    assert df.vars()["spoken"] == "B"
    df.user_turn("b")
    df.system_turn()
    assert df.state() == States.C
    assert df.vars()["spoken"] == "C"
    expected_gates = {"States.B": [{}], "States.C": [{"spoken": "B"}]}
    assert df.gates() == expected_gates
    df.vars()["testing_none"] = None
    d = df.serialize()

    df2 = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df2.add_state(States.B, error_successor=States.E)
    df2.add_state(States.C, error_successor=States.E)
    df2.add_system_transition(States.A, States.B, "#GATE $spoken=B")
    df2.add_system_transition(States.A, States.C, "#GATE(spoken) $spoken=C")
    df2.add_system_transition(States.E, States.E, "$spoken=E")
    df2.add_user_transition(States.B, States.A, "$heard=b")
    df2.add_user_transition(States.E, States.A, "$heard=e")
    assert df2.state() == States.A
    assert "spoken" not in df2.vars() and "heard" not in df2.vars()
    assert len(df2.gates()) == 0

    df2.deserialize(d)

    assert df.vars() == df2.vars()
    assert df.gates() == df2.gates()
    assert df.state() == df2.state()
    assert df2.vars()["testing_none"] is None
Exemplo n.º 2
0
def test_serialization():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.E)
    df.add_state(States.C, error_successor=States.E)
    df.add_system_transition(States.A, States.B, '#GATE $spoken=B')
    df.add_system_transition(States.A, States.C, '#GATE(spoken) $spoken=C')
    df.add_system_transition(States.E, States.E, '$spoken=E')
    df.add_user_transition(States.B, States.A, '$heard=b')
    df.add_user_transition(States.E, States.A, '$heard=e')

    df.system_turn()
    assert df.state() == States.B
    assert df.vars()["spoken"] == "B"
    df.user_turn('b')
    df.system_turn()
    assert df.state() == States.C
    assert df.vars()["spoken"] == "C"
    expected_gates = {'States.B': [{}], 'States.C': [{'spoken': 'B'}]}
    assert df.gates() == expected_gates
    df.vars()["testing_none"] = None
    d = df.serialize()

    df2 = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df2.add_state(States.B, error_successor=States.E)
    df2.add_state(States.C, error_successor=States.E)
    df2.add_system_transition(States.A, States.B, '#GATE $spoken=B')
    df2.add_system_transition(States.A, States.C, '#GATE(spoken) $spoken=C')
    df2.add_system_transition(States.E, States.E, '$spoken=E')
    df2.add_user_transition(States.B, States.A, '$heard=b')
    df2.add_user_transition(States.E, States.A, '$heard=e')
    assert df2.state() == States.A
    assert 'spoken' not in df2.vars() and 'heard' not in df2.vars()
    assert len(df2.gates()) == 0

    df2.deserialize(d)

    assert df.vars() == df2.vars()
    assert df.gates() == df2.gates()
    assert df.state() == df2.state()
    assert df2.vars()["testing_none"] is None