-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More meta tests for
test_signatures.py
- Loading branch information
Showing
1 changed file
with
61 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,70 @@ | ||
from inspect import signature | ||
from inspect import Parameter, Signature, signature | ||
|
||
import pytest | ||
|
||
from ..test_signatures import _test_inspectable_func | ||
|
||
|
||
@pytest.mark.xfail("not implemented") | ||
def test_kwonly(): | ||
def func(*, foo=None, bar=None): | ||
pass | ||
def stub(foo, /, bar=None, *, baz=None): | ||
pass | ||
|
||
sig = signature(func) | ||
_test_inspectable_func(sig, sig) | ||
|
||
def reversed_func(*, bar=None, foo=None): | ||
pass | ||
stub_sig = signature(stub) | ||
|
||
reversed_sig = signature(reversed_func) | ||
_test_inspectable_func(sig, reversed_sig) | ||
|
||
@pytest.mark.parametrize( | ||
"sig", | ||
[ | ||
Signature( | ||
[ | ||
Parameter("foo", Parameter.POSITIONAL_ONLY), | ||
Parameter("bar", Parameter.POSITIONAL_OR_KEYWORD), | ||
Parameter("baz", Parameter.KEYWORD_ONLY), | ||
] | ||
), | ||
Signature( | ||
[ | ||
Parameter("foo", Parameter.POSITIONAL_ONLY), | ||
Parameter("bar", Parameter.POSITIONAL_OR_KEYWORD), | ||
Parameter("baz", Parameter.POSITIONAL_OR_KEYWORD), | ||
] | ||
), | ||
pytest.param( | ||
Signature( | ||
[ | ||
Parameter("foo", Parameter.POSITIONAL_ONLY), | ||
Parameter("bar", Parameter.POSITIONAL_OR_KEYWORD), | ||
Parameter("qux", Parameter.KEYWORD_ONLY), | ||
Parameter("baz", Parameter.KEYWORD_ONLY), | ||
] | ||
), | ||
marks=pytest.mark.xfail(reason="out-of-order kwonly args not supported"), | ||
), | ||
], | ||
) | ||
def test_good_sig_passes(sig): | ||
_test_inspectable_func(sig, stub_sig) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"sig", | ||
[ | ||
Signature( | ||
[ | ||
Parameter("foo", Parameter.POSITIONAL_ONLY), | ||
Parameter("bar", Parameter.POSITIONAL_ONLY), | ||
Parameter("baz", Parameter.KEYWORD_ONLY), | ||
] | ||
), | ||
Signature( | ||
[ | ||
Parameter("foo", Parameter.POSITIONAL_ONLY), | ||
Parameter("bar", Parameter.KEYWORD_ONLY), | ||
Parameter("baz", Parameter.KEYWORD_ONLY), | ||
] | ||
), | ||
], | ||
) | ||
def test_raises_on_bad_sig(sig): | ||
with pytest.raises(AssertionError): | ||
_test_inspectable_func(sig, stub_sig) |