def test_container_feature_lookup_works_if_messages_are_broken_but_consistent(): not_broken_but_strange_table = MessageContainerForCoreFeaturization() not_broken_but_strange_table._table = { TEXT: {"A": Message(data=dict())}, INTENT: {"B": Message(data=dict(), features=[_dummy_features(1, TEXT)])}, } features = not_broken_but_strange_table.collect_features({TEXT: "A", INTENT: "B"}) assert TEXT in features and len(features[TEXT]) == 1
def test_container_feature_lookup_fails_if_different_features_for_same_attribute(): broken_table = MessageContainerForCoreFeaturization() broken_table._table = { TEXT: {"A": Message(data={}, features=[_dummy_features(2, TEXT)])}, INTENT: {"B": Message(data={}, features=[_dummy_features(1, TEXT)])}, } with pytest.raises( RuntimeError, match=f"Feature for attribute {TEXT} has already been" ): broken_table.collect_features({TEXT: "A", INTENT: "B"})