Skip to content

Commit

Permalink
More meta tests for test_signatures.py
Browse files Browse the repository at this point in the history
  • Loading branch information
honno committed Apr 13, 2022
1 parent 447ecea commit 707eed9
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions array_api_tests/meta/test_signatures.py
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)

0 comments on commit 707eed9

Please sign in to comment.