def test_container_message_lookup(): # create some messages with unique key attributes messages = [ Message(data={TEXT: "A"}, features=[_dummy_features(1, TEXT)]), Message(data={TEXT: "B"}), Message(data={INTENT: "B"}), Message(data={ACTION_TEXT: "B"}), Message(data={ACTION_NAME: "B"}), ] # add messages to container table = MessageContainerForCoreFeaturization() table.add_all(messages) # lookup messages using existing texts message = table.lookup_message(user_text="A") assert message assert len(message.data) == 1 assert len(message.features) == 1 message = table.lookup_message(user_text="B") assert message assert len(message.data) == 1
def test_container_message_lookup_fails_if_text_cannot_be_looked_up(): table = MessageContainerForCoreFeaturization() with pytest.raises(ValueError, match="Expected a message with key"): table.lookup_message(user_text="a text not included in the table")