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
Add async method mock #148
base: master
Are you sure you want to change the base?
Conversation
Not sure this is the best way to do it. please let me know if you have comments |
55f1d0a
to
d101207
Compare
d101207
to
1adcccd
Compare
@MetalHurlant, thanks for the PR! Some comments:
Anyway, this looks like a simple an pragmatic way to add async support to flexmock 👍 @christophe-riolo, @adarshk7 what do you think? |
Thanks for the comments. I will update the PR. |
I had a quick glance it looks like a nice change, I'll look more in detail asap ! |
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.
Thank you very much for your contribution 🙏
I have a couple of questions and suggestions, but overall I like the way you have designed this addition 👍
@@ -778,6 +797,14 @@ def _match_args(self, given_args: Any) -> bool: | |||
return False | |||
return True | |||
|
|||
def _verify_not_async_spy(self): | |||
"""Check if trying to assert the output of an async call.""" | |||
is_spy = self._replace_with is self.__dict__.get("_original") |
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 am thinking, this could potentially be extracted in a property, maybe outside of this PR what do you think @ollipa ?
@@ -872,6 +899,7 @@ def and_return(self, *values: Any) -> "Expectation": | |||
>>> plane.passenger_count() | |||
3 | |||
""" | |||
self._verify_not_async_spy() |
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.
Do we really need to forbid this ? It feels like we could check the result of the spied function in an asynchronous way. It could require more work that could be on us @ollipa
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.
We could forbid it now and allow it in the future when we make an implementation for it.
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.
As olippa said. For now it would not work properly so I preferred raising a clear error.
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.
Yes, that's what I was suggesting, but so we could create an issue for that 👍
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #148 +/- ##
===========================================
- Coverage 100.00% 99.53% -0.47%
===========================================
Files 4 4
Lines 834 863 +29
===========================================
+ Hits 834 859 +25
- Misses 0 4 +4 ☔ View full report in Codecov by Sentry. |
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 made a few comments comments but overall looks very good!
"pypy-3.8", | ||
"pypy-3.9", | ||
"3.7", |
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.
It seems that Pypy has released 3.10 version. You can include that here.
@@ -57,7 +55,7 @@ jobs: | |||
- name: Set up Python | |||
uses: actions/setup-python@v4 | |||
with: | |||
python-version: "3.7" | |||
python-version: "3.11" |
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 tests are meant to be executed with the lowest Python version we support. Otherwise
python-version: "3.11" | |
python-version: "3.8" |
@@ -89,7 +87,7 @@ jobs: | |||
- name: Set up Python | |||
uses: actions/setup-python@v4 | |||
with: | |||
python-version: "3.7" | |||
python-version: "3.11" |
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.
python-version: "3.11" | |
python-version: "3.8" |
@@ -21,7 +21,7 @@ jobs: | |||
- name: Set up Python | |||
uses: actions/setup-python@v4 | |||
with: | |||
python-version: "3.7" | |||
python-version: "3.11" |
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.
python-version: "3.11" | |
python-version: "3.8" |
- Python 3.8 | ||
- Python 3.9 | ||
- Python 3.10 | ||
- Python 3.11 |
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.
You can also add Python 3.12 here.
@@ -28,6 +28,24 @@ | |||
RE_TYPE = type(re.compile("")) | |||
|
|||
|
|||
async def future_raise(anything: type[BaseException]) -> 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.
Using type
directly requires Python 3.9.
async def future_raise(anything: type[BaseException]) -> None: | |
async def future_raise(anything: Type[BaseException]) -> None: |
@@ -28,6 +28,24 @@ | |||
RE_TYPE = type(re.compile("")) | |||
|
|||
|
|||
async def future_raise(anything: type[BaseException]) -> 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.
I guess we don't need these functions to be part of the public API?
async def future_raise(anything: type[BaseException]) -> None: | |
async def _future_raise(anything: type[BaseException]) -> None: |
raise anything | ||
|
||
|
||
async def future(anything: Any) -> Any: |
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.
async def future(anything: Any) -> Any: | |
async def _future(anything: Any) -> Any: |
"""Set the return values of the expectation to coroutines | ||
Need to be set before the return value is set |
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.
"""Set the return values of the expectation to coroutines | |
Need to be set before the return value is set | |
"""Set the return value to be a coroutine. | |
Needs to be set before the return value is set. |
|
||
def make_sync(self) -> "Expectation": | ||
"""Make the mocked method synchronous. | ||
Need to be set before the return value is set |
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 be set before the return value is set | |
Needs to be set before the return value is set. |
@MetalHurlant, if you rebase your changes you can remove |
No description provided.