diff --git a/array_api_tests/meta/test_signatures.py b/array_api_tests/meta/test_signatures.py index 1e34d176..f6f40a4c 100644 --- a/array_api_tests/meta/test_signatures.py +++ b/array_api_tests/meta/test_signatures.py @@ -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)