-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and updated documentation about creation from
Signature
…
… instances
- Loading branch information
Sylvain MARIE
committed
Feb 1, 2019
1 parent
a2945f2
commit ccd2cff
Showing
3 changed files
with
165 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
from makefun import create_function | ||
|
||
try: # python 3.3+ | ||
from inspect import signature, Signature, Parameter | ||
except ImportError: | ||
from funcsigs import signature, Signature, Parameter | ||
|
||
|
||
def my_handler(*args, **kwargs): | ||
"""This docstring will be used in the generated function by default""" | ||
print("my_handler called !") | ||
return args, kwargs | ||
|
||
|
||
def test_positional_only(): | ||
"""Tests that as of today one cannot create positional-only functions""" | ||
|
||
params = [Parameter('a', kind=Parameter.POSITIONAL_ONLY), | ||
Parameter('args', kind=Parameter.VAR_POSITIONAL), | ||
Parameter('kwargs', kind=Parameter.VAR_KEYWORD)] | ||
|
||
func_signature = Signature(parameters=params) | ||
|
||
with pytest.raises(SyntaxError): | ||
dynamic_fun = create_function(func_signature, my_handler, func_name="foo") | ||
print(dynamic_fun.__source__) | ||
assert dynamic_fun(0, 1) == ((1,), {'a': 0}) |
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