-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat: integer repeat #237
feat: integer repeat #237
Conversation
aioresponses/core.py
Outdated
@@ -471,6 +471,10 @@ async def match( | |||
|
|||
if matcher.repeat is False: | |||
del self._matches[key] | |||
elif matcher.repeat == 2: |
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 equal to 2?
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 I meant repeat=1
to have the same effect as repeat=False
. That is, I interpret the number of repetitions to include the first call. I guess an alternative would be to define the number of repetitions as the number after the first call.
That is, for repeat=5
, either:
- respond 5 times with foo
- respond with foo, and also do that the next 5 times (so 6 in total)
The former seems more intuitive to me.
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.
The repeat=1
case was actually broken. I fixed it and added a test. I also elaborated on this matter in the main README.
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
This feature would be very much appreciated 👍 |
aioresponses/core.py
Outdated
@@ -469,8 +469,12 @@ async def match( | |||
else: | |||
return None | |||
|
|||
if matcher.repeat is False: | |||
if matcher.repeat in (False, 1): |
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.
test are not working and this part is bugged.
when repeat is set to True the if statement does not work [True in (False, 1) returns True].
IMO we should have
if isinstance(matcher.repeat, bool):
if not matcher.repeat:
del self._matches[key]
else:
if matcher.repeat == 1:
del self._matches[key]
matcher.repeat -= 1
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.
Great suggestion, much cleaner. I'll gladly fix it. Just give me a few days, please (got a project deadline).
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 to fix tests. Let me know if you fix this or should I fixed this :) ?
if isinstance(matcher.repeat, bool):
if not matcher.repeat:
del self._matches[key]
else:
if matcher.repeat == 1:
del self._matches[key]
matcher.repeat -= 1
Closes #234.