adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Add unit tests for example_util.convert_examples_to_text

Open xxlest opened this issue 9 months ago • 4 comments

Summary

src/google/adk/examples/example_util.py:49 has a TODO from the original author:

# TODO(yaojie): Add unit tests for this function.
def convert_examples_to_text(examples: list[Example], model: Optional[str]) -> str:

This function handles few-shot example formatting for system instructions and currently has zero test coverage. The related build_example_si and _get_latest_message_from_user helpers are also untested.

Proposed test cases

  • Basic text-only examples
  • Function call + function response formatting
  • Mixed content (text + function call)
  • Empty examples list
  • Gemini 2 vs non-Gemini 2 format branch (_FUNCTION_PREFIX vs _FUNCTION_CALL_PREFIX)
  • build_example_si with list input vs BaseExampleProvider input
  • _get_latest_message_from_user with empty session, non-user author, function responses

Happy to submit a PR for this.

xxlest avatar Feb 25 '26 14:02 xxlest

@xxlest the TODO at example_util.py:49 has been there since the file was written and these three functions have zero coverage, so a PR here is definitely welcome.

Target file would be tests/unittests/examples/test_example_util.py (the directory doesn't exist yet, so you'll need to add an __init__.py alongside it).

The proposed cases look solid; just make sure the Gemini-2 vs non-Gemini-2 prefix branch is covered for both function calls and function responses separately, as those follow different code paths at lines 79 and 85.

Run with pytest tests/unittests/examples/ from the repo root once the file is in place.

surajksharma07 avatar Feb 25 '26 16:02 surajksharma07

@Jacksunwei PTAL.

surajksharma07 avatar Feb 25 '26 16:02 surajksharma07

I can start working on a PR.

BowedMars2 avatar Mar 05 '26 19:03 BowedMars2

I'm noticing build_example_si takes an argument for query even though it's not used if you pass in a list rather than a BaseExampleProvider. Is this expected behavior that is there for a reason, or should I open an issue for this?

BowedMars2 avatar Mar 12 '26 17:03 BowedMars2