-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update makefun version * implement proper forwarding of async * rename new files * make parametrize async aware * Add tests * Add pytest ignore_glob for python < 3.6
- Loading branch information
Showing
11 changed files
with
332 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Authors: Sylvain MARIE <[email protected]> | ||
# + All contributors to <https://github.com/smarie/python-pytest-cases> | ||
# | ||
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE> | ||
|
||
# contains syntax illegal before PEP380 'Syntax for Delegating to a Subgenerator' | ||
|
||
from makefun import wraps | ||
from .fixture_core1_unions import is_used_request, NOT_USED | ||
|
||
|
||
def _ignore_unused_generator_pep380(fixture_func, new_sig, func_needs_request): | ||
@wraps(fixture_func, new_sig=new_sig) | ||
def wrapped_fixture_func(*args, **kwargs): | ||
request = kwargs['request'] if func_needs_request else kwargs.pop('request') | ||
if is_used_request(request): | ||
yield from fixture_func(*args, **kwargs) | ||
else: | ||
yield NOT_USED | ||
|
||
return wrapped_fixture_func | ||
|
||
def _decorate_fixture_plus_generator_pep380(fixture_func, new_sig, map_arguments): | ||
@wraps(fixture_func, new_sig=new_sig) | ||
def wrapped_fixture_func(*_args, **_kwargs): | ||
if not is_used_request(_kwargs['request']): | ||
yield NOT_USED | ||
else: | ||
_args, _kwargs = map_arguments(*_args, **_kwargs) | ||
yield from fixture_func(*_args, **_kwargs) | ||
|
||
return wrapped_fixture_func | ||
|
||
def _parametrize_plus_decorate_generator_pep380( | ||
test_func, | ||
new_sig, | ||
fixture_union_name, | ||
replace_paramfixture_with_values | ||
): | ||
@wraps(test_func, new_sig=new_sig) | ||
def wrapped_test_func(*args, **kwargs): # noqa | ||
if kwargs.get(fixture_union_name, None) is NOT_USED: | ||
# TODO why this ? it is probably useless: this fixture | ||
# is private and will never end up in another union | ||
yield NOT_USED | ||
else: | ||
replace_paramfixture_with_values(kwargs) | ||
yield from test_func(*args, **kwargs) | ||
|
||
return wrapped_test_func |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Authors: Sylvain MARIE <[email protected]> | ||
# + All contributors to <https://github.com/smarie/python-pytest-cases> | ||
# | ||
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE> | ||
|
||
# contains syntax illegal before PEP492 "Coroutines with async and await syntax" | ||
|
||
from makefun import wraps | ||
from .fixture_core1_unions import is_used_request, NOT_USED | ||
|
||
|
||
def _ignore_unused_coroutine_pep492(fixture_func, new_sig, func_needs_request): | ||
@wraps(fixture_func, new_sig=new_sig) | ||
async def wrapped_fixture_func(*args, **kwargs): | ||
request = kwargs['request'] if func_needs_request else kwargs.pop('request') | ||
if is_used_request(request): | ||
return await fixture_func(*args, **kwargs) | ||
else: | ||
return NOT_USED | ||
|
||
return wrapped_fixture_func | ||
|
||
def _decorate_fixture_plus_coroutine_pep492(fixture_func, new_sig, map_arguments): | ||
@wraps(fixture_func, new_sig=new_sig) | ||
async def wrapped_fixture_func(*_args, **_kwargs): | ||
if not is_used_request(_kwargs['request']): | ||
return NOT_USED | ||
else: | ||
_args, _kwargs = map_arguments(*_args, **_kwargs) | ||
return await fixture_func(*_args, **_kwargs) | ||
|
||
return wrapped_fixture_func | ||
|
||
def _parametrize_plus_decorate_coroutine_pep492( | ||
test_func, | ||
new_sig, | ||
fixture_union_name, | ||
replace_paramfixture_with_values | ||
): | ||
@wraps(test_func, new_sig=new_sig) | ||
async def wrapped_test_func(*args, **kwargs): # noqa | ||
if kwargs.get(fixture_union_name, None) is NOT_USED: | ||
# TODO why this ? it is probably useless: this fixture | ||
# is private and will never end up in another union | ||
return NOT_USED | ||
else: | ||
replace_paramfixture_with_values(kwargs) | ||
return await test_func(*args, **kwargs) | ||
|
||
return wrapped_test_func |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Authors: Sylvain MARIE <[email protected]> | ||
# + All contributors to <https://github.com/smarie/python-pytest-cases> | ||
# | ||
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE> | ||
|
||
# contains syntax illegal before PEP525 "Asynchronous Generators" | ||
|
||
from makefun import wraps | ||
from .fixture_core1_unions import is_used_request, NOT_USED | ||
|
||
|
||
def _ignore_unused_asyncgen_pep525(fixture_func, new_sig, func_needs_request): | ||
@wraps(fixture_func, new_sig=new_sig) | ||
async def wrapped_fixture_func(*args, **kwargs): | ||
request = kwargs['request'] if func_needs_request else kwargs.pop('request') | ||
if is_used_request(request): | ||
async for res in fixture_func(*args, **kwargs): | ||
yield res | ||
else: | ||
yield NOT_USED | ||
|
||
return wrapped_fixture_func | ||
|
||
def _decorate_fixture_plus_asyncgen_pep525(fixture_func, new_sig, map_arguments): | ||
@wraps(fixture_func, new_sig=new_sig) | ||
async def wrapped_fixture_func(*_args, **_kwargs): | ||
if not is_used_request(_kwargs['request']): | ||
yield NOT_USED | ||
else: | ||
_args, _kwargs = map_arguments(*_args, **_kwargs) | ||
async for res in fixture_func(*_args, **_kwargs): | ||
yield res | ||
|
||
return wrapped_fixture_func | ||
|
||
def _parametrize_plus_decorate_asyncgen_pep525( | ||
test_func, | ||
new_sig, | ||
fixture_union_name, | ||
replace_paramfixture_with_values | ||
): | ||
@wraps(test_func, new_sig=new_sig) | ||
async def wrapped_test_func(*args, **kwargs): # noqa | ||
if kwargs.get(fixture_union_name, None) is NOT_USED: | ||
# TODO why this ? it is probably useless: this fixture | ||
# is private and will never end up in another union | ||
yield NOT_USED | ||
else: | ||
replace_paramfixture_with_values(kwargs) | ||
async for res in test_func(*args, **kwargs): | ||
yield res | ||
|
||
return wrapped_test_func |
Oops, something went wrong.