Adds missing unit tests (Issue #4623)#4802
Conversation
|
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. |
Summary of ChangesHello, 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 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
|
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! |
There was a problem hiding this comment.
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. |
| 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 |
There was a problem hiding this comment.
| 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__}" |
There was a problem hiding this comment.
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.
|
Hi @BowedMars2 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. |
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:
Testing Plan
I ran the tests personally, and they successfully passed.
Unit Tests:
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
Additional context