def test_container_add_message_copies(): # construct a set of unique substates and messages dummy_value = "this-could-be-anything" substates_with_unique_key_attribute = [ {INTENT: "greet"}, {TEXT: "text", ENTITIES: dummy_value}, {TEXT: "other-text"}, {ACTION_TEXT: "action_text"}, {ACTION_NAME: "action_name"}, ] unique_messages = [ Message(sub_state) for sub_state in substates_with_unique_key_attribute ] # make some copies num_copies = 3 messages = unique_messages * (1 + num_copies) # build table lookup_table = MessageContainerForCoreFeaturization() for message in messages: lookup_table.add(message) # assert that we have as many entries as unique keys assert len(lookup_table) == len(substates_with_unique_key_attribute) assert set(lookup_table.all_messages()) == set(unique_messages) assert ( lookup_table.num_collisions_ignored == len(substates_with_unique_key_attribute) * num_copies )
def test_container_all_messages(): message_data_list = [{INTENT: "1"}, {INTENT: "2", "other": 3}, {TEXT: "3"}] container = MessageContainerForCoreFeaturization() container.add_all([Message(data=data) for data in message_data_list]) assert len(container.all_messages()) == 3