def test_evaluate_prepares_dataframe_correctly_for_perform_eval(
      self, mock_perform_eval
  ):
    """Test that the DataFrame is correctly flattened and renamed before passing to _perform_eval."""
    mock_perform_eval.return_value = MOCK_EVAL_RESULT

    raw_data = [
        [SAMPLE_TURN_1_ALL_KEYS],  # Conversation 1
        [
            SAMPLE_TURN_2_MISSING_REF,
            SAMPLE_TURN_3_MISSING_EXP_TOOLS,
        ],  # Conversation 2
    ]
    criteria = [
        "response_match_score"
    ]  # Doesn't affect the DataFrame structure

    ResponseEvaluator.evaluate(raw_data, criteria)

    # Expected flattened and renamed data
    expected_df_data = [
        # Turn 1 (from SAMPLE_TURN_1_ALL_KEYS)
        {
            "prompt": "query1",
            "response": "response1",
            "actual_tool_use": [{"tool_name": "tool_a", "tool_input": {}}],
            "reference_trajectory": [{"tool_name": "tool_a", "tool_input": {}}],
            "reference": "reference1",
        },
        # Turn 2 (from SAMPLE_TURN_2_MISSING_REF)
        {
            "prompt": "query2",
            "response": "response2",
            "actual_tool_use": [],
            "reference_trajectory": [],
            # "reference": None # Missing key results in NaN in DataFrame
            # usually
        },
        # Turn 3 (from SAMPLE_TURN_3_MISSING_EXP_TOOLS)
        {
            "prompt": "query3",
            "response": "response3",
            "actual_tool_use": [{"tool_name": "tool_b", "tool_input": {}}],
            # "reference_trajectory": None, # Missing key results in NaN
            "reference": "reference3",
        },
    ]
    # Need to be careful with missing keys -> NaN when creating DataFrame
    # Pandas handles this automatically when creating from list of dicts
    expected_df = pd.DataFrame(expected_df_data)

    mock_perform_eval.assert_called_once()
    _, kwargs = mock_perform_eval.call_args
    # Compare the DataFrame passed to the mock
    pd.testing.assert_frame_equal(kwargs["dataset"], expected_df)
Test that the DataFrame is correctly flattened and renamed before passing to _perform_eval.
tests/unittests/evaluation/test_response_evaluator.py