|
1 |
| -from inspect import signature |
| 1 | +from inspect import Parameter, Signature, signature |
2 | 2 |
|
3 | 3 | import pytest
|
4 | 4 |
|
5 | 5 | from ..test_signatures import _test_inspectable_func
|
6 | 6 |
|
7 | 7 |
|
8 |
| -@pytest.mark.xfail("not implemented") |
9 |
| -def test_kwonly(): |
10 |
| - def func(*, foo=None, bar=None): |
11 |
| - pass |
| 8 | +def stub(foo, /, bar=None, *, baz=None): |
| 9 | + pass |
12 | 10 |
|
13 |
| - sig = signature(func) |
14 |
| - _test_inspectable_func(sig, sig) |
15 | 11 |
|
16 |
| - def reversed_func(*, bar=None, foo=None): |
17 |
| - pass |
| 12 | +stub_sig = signature(stub) |
18 | 13 |
|
19 |
| - reversed_sig = signature(reversed_func) |
20 |
| - _test_inspectable_func(sig, reversed_sig) |
| 14 | + |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "sig", |
| 17 | + [ |
| 18 | + Signature( |
| 19 | + [ |
| 20 | + Parameter("foo", Parameter.POSITIONAL_ONLY), |
| 21 | + Parameter("bar", Parameter.POSITIONAL_OR_KEYWORD), |
| 22 | + Parameter("baz", Parameter.KEYWORD_ONLY), |
| 23 | + ] |
| 24 | + ), |
| 25 | + Signature( |
| 26 | + [ |
| 27 | + Parameter("foo", Parameter.POSITIONAL_ONLY), |
| 28 | + Parameter("bar", Parameter.POSITIONAL_OR_KEYWORD), |
| 29 | + Parameter("baz", Parameter.POSITIONAL_OR_KEYWORD), |
| 30 | + ] |
| 31 | + ), |
| 32 | + pytest.param( |
| 33 | + Signature( |
| 34 | + [ |
| 35 | + Parameter("foo", Parameter.POSITIONAL_ONLY), |
| 36 | + Parameter("bar", Parameter.POSITIONAL_OR_KEYWORD), |
| 37 | + Parameter("qux", Parameter.KEYWORD_ONLY), |
| 38 | + Parameter("baz", Parameter.KEYWORD_ONLY), |
| 39 | + ] |
| 40 | + ), |
| 41 | + marks=pytest.mark.xfail(reason="out-of-order kwonly args not supported"), |
| 42 | + ), |
| 43 | + ], |
| 44 | +) |
| 45 | +def test_good_sig_passes(sig): |
| 46 | + _test_inspectable_func(sig, stub_sig) |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.parametrize( |
| 50 | + "sig", |
| 51 | + [ |
| 52 | + Signature( |
| 53 | + [ |
| 54 | + Parameter("foo", Parameter.POSITIONAL_ONLY), |
| 55 | + Parameter("bar", Parameter.POSITIONAL_ONLY), |
| 56 | + Parameter("baz", Parameter.KEYWORD_ONLY), |
| 57 | + ] |
| 58 | + ), |
| 59 | + Signature( |
| 60 | + [ |
| 61 | + Parameter("foo", Parameter.POSITIONAL_ONLY), |
| 62 | + Parameter("bar", Parameter.KEYWORD_ONLY), |
| 63 | + Parameter("baz", Parameter.KEYWORD_ONLY), |
| 64 | + ] |
| 65 | + ), |
| 66 | + ], |
| 67 | +) |
| 68 | +def test_raises_on_bad_sig(sig): |
| 69 | + with pytest.raises(AssertionError): |
| 70 | + _test_inspectable_func(sig, stub_sig) |
0 commit comments