Skip to content

Adds missing unit tests (Issue #4623)#4802

Open
BowedMars2 wants to merge 11 commits intogoogle:mainfrom
BowedMars374878:Issue-#4623
Open

Adds missing unit tests (Issue #4623)#4802
BowedMars2 wants to merge 11 commits intogoogle:mainfrom
BowedMars374878:Issue-#4623

Conversation

@BowedMars2
Copy link

@BowedMars2 BowedMars2 commented Mar 12, 2026

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Problem:
example_util.py was completely missing unit tests.

Solution:
I added unit tests for a variety of situations:

  • Converting a text-only example to a string
  • Converting a text-only example with multiple Parts to a string
  • Converting a text-only example to a string when the output contains a conversation between the user and model
  • Converting another text-only example with a conversational output, but with clumped messages from each
  • Converting an empty list to a string
  • Converting an example including a function call to a string
  • Converting an example including a function response to a string
  • Converting an example including both a function call and a function response to a string
  • Converting an example with text, a function call, and a function response to a string
  • Building System Information from a list of examples
  • Building System Information from an example provider

Testing Plan

I ran the tests personally, and they successfully passed.

Unit Tests:

  • [✓] I have added or updated unit tests for my change.
  • [✓] All unit tests pass locally.

33 passed in 2.55s

Manual End-to-End (E2E) Tests:

To test my change, simply run the unit tests and they should pass. If you want to verify the effectiveness of my tests, try modifying the input given to my unit tests and see if they fail.

Checklist

  • [✓] I have read the CONTRIBUTING.md document.
  • [✓] I have performed a self-review of my own code.
  • [✓] I have commented my code, particularly in hard-to-understand areas.
  • [✓] I have added tests that prove my fix is effective or that my feature works.
  • [✓] New and existing unit tests pass locally with my changes.
  • [✓] I have manually tested my changes end-to-end.
  • [✓] Any dependent changes have been merged and published in downstream modules.

Additional context

  • I noticed 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?
  • I also noticed that when model is None, it defaults to Gemini 2. This seems like it could cause issues on the user end. Is there a reason for this functionality?

@google-cla
Copy link

google-cla bot commented Mar 12, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and reliability of the example_util.py module by introducing a comprehensive suite of unit tests. The added tests validate the correct conversion of various Example objects into text formats suitable for system instructions, covering a wide range of input complexities and ensuring the module behaves as expected under different conditions.

Highlights

  • Improved Test Coverage: Added comprehensive unit tests for the example_util.py module, which previously lacked test coverage.
  • Diverse Test Scenarios: Introduced tests covering various Example conversion scenarios, including text-only, multi-part text, conversational outputs, empty example lists, and examples involving function calls and responses.
  • System Information Building Tests: Included tests for building system information from both lists of examples and BaseExampleProvider instances.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/google/adk/examples/example_util.py
    • Removed a TODO comment indicating the absence of unit tests for the convert_examples_to_text function, as tests have now been added.
  • tests/unittests/examples/init.py
    • Added a new __init__.py file to properly define the examples directory as a Python package within the test suite.
  • tests/unittests/examples/test_example_util.py
    • Added a new test file containing extensive unit tests for example_util.py.
    • Implemented tests for converting text-only examples, including those with multiple parts and conversational outputs.
    • Included tests for handling empty example lists.
    • Developed tests for examples containing function calls and function responses, both individually and combined.
    • Added tests for the build_example_si function, verifying its behavior with both example lists and BaseExampleProvider instances.
Activity
  • The author, BowedMars2, identified a lack of unit tests for example_util.py (Issue Add unit tests for example_util.convert_examples_to_text #4623) and provided a solution.
  • BowedMars2 implemented a comprehensive set of unit tests covering various scenarios for example conversion and system information building.
  • The author confirmed that all unit tests were run personally and passed successfully locally.
  • BowedMars2 performed a self-review, commented the code, and ensured all checklist items were addressed.
  • The author raised questions regarding the query argument in build_example_si when a list is passed, and the default model behavior when None is provided, seeking clarification on expected behavior or potential issues.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Mar 12, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Mar 12, 2026

Response from ADK Triaging Agent

Hello @BowedMars2, thank you for your contribution!

It looks like you haven't signed the Contributor License Agreement (CLA) yet. Please visit https://cla.developers.google.com/ to sign it. Once you have signed the CLA, the status of the PR will be updated.

Thanks!

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a comprehensive suite of unit tests for example_util.py, which was previously untested. The changes are a great addition and significantly improve test coverage. I've made a few suggestions in the new test file to improve maintainability and robustness, mainly regarding the use of fixtures to reduce code duplication and avoiding fragile patterns like __dict__ for object serialization. There's also a minor docstring correction.

"""

def __init__(self, test_examples: list[example.Example], test_query: str) -> None:
"""Initializes a MockBlob.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The docstring incorrectly refers to MockBlob. It should be MockExampleProvider.

Suggested change
"""Initializes a MockBlob.
"""Initializes a MockExampleProvider.

Comment on lines +64 to +88
def test_text_only_example_conversion(model):
"""Tests converting a text-only Example object to a string for use in a system instruction."""
input_content = types.Content(
role="user",
parts=[types.Part(text="test_input")]
)
output_content = [types.Content(
role="model",
parts=[types.Part(text="test_output")]
)]
test_example = example.Example(
input=input_content,
output=output_content
)

expected_output = (
f"{example_util._EXAMPLES_INTRO}"
f"{example_util._EXAMPLE_START.format(1)}"
f"{example_util._USER_PREFIX}test_input\n"
f"{example_util._MODEL_PREFIX}test_output\n"
f"{example_util._EXAMPLE_END}"
f"{example_util._EXAMPLES_END}"
)

assert example_util.convert_examples_to_text(examples=[test_example], model=model) == expected_output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Many tests in this file repeat the setup for creating Example objects. To improve readability and maintainability, consider using pytest fixtures to generate these common test objects. This will reduce boilerplate code and make the tests easier to understand and maintain.

f"{example_util._EXAMPLE_START.format(1)}"
f"{example_util._USER_PREFIX}test_input\n"
f"{example_util._MODEL_PREFIX}{prefix}"
f"{test_function_response.__dict__}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using __dict__ to create a string representation of test_function_response is fragile, as it relies on the internal implementation details of the types.FunctionResponse class. This pattern is repeated in other tests as well. While this test correctly mirrors the behavior of the code under test, both are susceptible to breaking if the google-genai library changes. A more robust approach would be to use a public serialization method. It would be good to create a follow-up issue to address this fragility in both the production code and the tests.

@rohityan rohityan self-assigned this Mar 12, 2026
@rohityan
Copy link
Collaborator

Hi @BowedMars2 , Thank you for your contribution! We appreciate you taking the time to submit this pull request.
Can you please fix the formatting errors. You can use autoformat.sh.

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for example_util.convert_examples_to_text

4 participants