Add unit tests for example_util.convert_examples_to_text
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_PREFIXvs_FUNCTION_CALL_PREFIX) build_example_siwith list input vsBaseExampleProviderinput_get_latest_message_from_userwith empty session, non-user author, function responses
Happy to submit a PR for this.
@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.
@Jacksunwei PTAL.
I can start working on a PR.
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?