-
Notifications
You must be signed in to change notification settings - Fork 48
ResultSet: add tests to cover paging with empty pages #104
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
Conversation
@@ -41,6 +41,19 @@ def test_iter_paged(self): | |||
type(response_future).has_more_pages = PropertyMock(side_effect=(True, True, False)) # after init to avoid side effects being consumed by init | |||
self.assertListEqual(list(itr), expected) | |||
|
|||
def test_iter_paged_with_empty_pages(self): | |||
expected = list(range(10)) | |||
response_future = Mock(has_more_pages=True, _continuous_paging_session=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it ok to always return has_more_pages==True? Shouldn't it return False for the last page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because stopIteration
will be raised anyway, so in the scope of this test, we do not need to add the complexity of chaging the paging state of the response future to demonstrate and test the fixed behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have a bad day because I don't see how it works.
If has_more_pages
is True
then the condition in this if
will be false and the exception won't be raised, no?
That in turn will lead to next
being called again recursively over and over gain, no?
or will the StopIteration
be thrown from fetch_next_page
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand it's not obvious sorry.
The StopIteration
comes from the mocked response_future.result() iterator over the configured side_effect
s.
In other words, the tests do iterate over the side_effect
s every time response_future.result()
is called in fetch_next_page()
, when all the side_effect
s (pages) have been depleted, the next call to response_future.result()
will raise a StopIteration
exception.
Does that make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. That's what I meant by StopIteration
being thrown from fetch_next_page
. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#need a pypi release plz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Related to #102