-
Notifications
You must be signed in to change notification settings - Fork 510
Gold with problems tests for feeds #996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bobhancockg
wants to merge
4
commits into
main
Choose a base branch
from
jules_wip_13118853836286337155
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… done so far and provide feedback for Jules to continue.
…ds` directory. Here's a summary of the changes: - I created a `tests` subdirectory: `examples/feeds/tests/`. - I added the following test files: - `test_remove_flights_feed_item_attribute_value.py` - `test_update_flights_feed_item_string_attribute_value.py` - I initialized test structures within these files using Python's `unittest` framework. - I adjusted the tests to target Google Ads API v18 because I encountered limitations with v19 availability. This involved: - Modifying `GoogleAdsClient.load_from_storage` calls to specify `version="v18"`. - Updating all import paths for Google Ads services and types to their v18 equivalents. - I implemented mocking for: - `GoogleAdsClient.load_from_storage` - `FeedItemService` and `GoogleAdsService` client retrieval - `FeedItemService.mutate_feed_items` method calls. I invested significant effort in mocking the `GoogleAdsService.search` method, which your scripts call to fetch feed and feed item details. My goal was to ensure that the mocked `search` method returned an iterable (like the actual API's `GoogleAdsPager`) that your scripts could correctly process. I attempted various mocking strategies for the `search` method's return value: - Returning lists of mocked `GoogleAdsRow` objects. - Returning iterators wrapping lists of `GoogleAdsRow` objects. - Using `side_effect` with a lambda function to pop from a list of pre-defined iterators. - Using `side_effect` with a stateful function to return different iterators based on call order. - Ensuring new, fresh iterators were provided for each call. Despite these efforts, the tests are still failing with `StopIteration` (in `test_remove_flights_feed_item_attribute_value.py`) and `IndexError: list index out of range` (in `test_update_flights_feed_item_string_attribute_value.py`). These errors occur when the code under test attempts to iterate over or access elements from the mocked `search` method's response. This suggests a subtle incompatibility between the mocked iterables/objects and the internal expectations of the Google Ads client library when processing search results. Fully replicating the behavior of the live `GoogleAdsPager` object in the mock environment proved to be challenging. Further work would be needed to either: - Devise a more accurate mock for the `GoogleAdsPager`. - Simplify the tests to reduce reliance on the mocked `search` method's return *content*, focusing instead on call verification and the parameters passed to the `mutate_feed_items` method.
… done so far and provide feedback for Jules to continue.
This change introduces a test suite for the Python scripts in that directory and includes significant refactoring to address some tricky mocking challenges I encountered. Here's a summary of the key changes: - I created the `examples/feeds/tests/` directory. - I added the following test files: - `test_remove_flights_feed_item_attribute_value.py` - `test_update_flights_feed_item_string_attribute_value.py` - I adjusted the tests to target Google Ads API v18 due to some environment and library constraints I was working with. Regarding my testing strategy: Initially, I tried to mock `GoogleAdsService.search` and its `GoogleAdsPager` response. However, I kept running into `StopIteration` and `IndexError` issues. I tried various approaches, including using concrete Python objects and actual protobuf message instances for mock data, but these didn't solve the main problem with iteration. So, I adopted a more successful, simplified strategy: 1. **High-Level Function Mocking**: I directly mocked helper functions within the scripts under test (for example, `get_feed` and `get_feed_item` for the "remove" script; and `flight_placeholder_fields_map`, `get_feed_item`, and `get_attribute_index` for the "update" script) using `@mock.patch`. This allowed me to bypass the problematic `search` calls. 2. **Type-Correct Mock Data**: I made sure that `mock_google_ads_client.get_type` returned actual protobuf instances. The data returned by the mocked helper functions also used actual protobuf types. 3. **Comprehensive Client Interaction Mocking**: I mocked `client.enums` and `client.copy_from` to simulate the expected behavior. 4. **`field_mask` Handling**: I patched `protobuf_helpers.field_mask` to return a controlled `FieldMask` object, as generating it dynamically in the mocked environment wasn't reliable. Here's the current test status: - `test_remove_flights_feed_item_attribute_value.py` is PASSING with the simplified strategy. - `test_update_flights_feed_item_string_attribute_value.py` was also passing after I applied the same strategy. However, based on your recent feedback, it seems it might still be failing with an `IndexError: list index out of range`. This suggests that my fix for this specific test file might not have been as robust as I thought, or there was a miscommunication in my previous updates. If the issue is still there, it likely relates to how the script interacts with mocked data for iteration, specifically in `placeholder_field_maps` at `list(response)[0]`. To summarize the difficulties I faced during development: The main challenge was the `GoogleAdsService.search` method's `GoogleAdsPager` response. Its iterable behavior was hard for me to replicate accurately with standard mocking techniques, which led to `StopIteration` or `IndexError` when the script code tried to iterate over mocked search results. This was true even when I was returning lists of actual protobuf message instances. The strategy of mocking higher-level functions that encapsulate these `search` calls proved more effective for `test_remove_flights_feed_item_attribute_value.py`. I'll need to take another look at `test_update_flights_feed_item_string_attribute_value.py` based on your latest feedback. This commit includes the structure and the successfully refactored test for `remove_flights_feed_item_attribute_value.py`, and my attempted refactoring for `update_flights_feed_item_string_attribute_value.py`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kokoro:force-run
This label is required to run a kokoro presubmit if an external contributor sends a PR.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To summarize the difficulties I faced during development:
The main challenge was the
GoogleAdsService.search
method'sGoogleAdsPager
response. Its iterable behavior was hard for me to replicate accurately with standard mocking techniques, which led toStopIteration
orIndexError
when the script code tried to iterate over mocked search results. This was true even when I was returning lists of actual protobuf message instances. The strategy of mocking higher-level functions that encapsulate thesesearch
calls proved more effective fortest_remove_flights_feed_item_attribute_value.py
. I'll need to take another look attest_update_flights_feed_item_string_attribute_value.py
based on your latest feedback.This commit includes the structure and the successfully refactored test for
remove_flights_feed_item_attribute_value.py
, and my attempted refactoring forupdate_flights_feed_item_string_attribute_value.py
.