summaryrefslogtreecommitdiff
path: root/ext/pybind11/tests/test_kwargs_and_defaults.py
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2017-05-09 19:22:53 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2017-05-22 17:15:09 +0000
commit6914a229a038206341ae1fea46393965a555ca9a (patch)
tree4a11cfaed46dabc827c5ee17cd976f42b5f53d49 /ext/pybind11/tests/test_kwargs_and_defaults.py
parentca1d18d599dcc620bf526fb22042af95b1b60b68 (diff)
downloadgem5-6914a229a038206341ae1fea46393965a555ca9a.tar.xz
ext: Upgrade PyBind11 to version 2.1.1
Change-Id: I16870dec402d661295f9d013dc23e362b2b2c169 Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Curtis Dunham <curtis.dunham@arm.com> Reviewed-on: https://gem5-review.googlesource.com/3225 Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'ext/pybind11/tests/test_kwargs_and_defaults.py')
-rw-r--r--ext/pybind11/tests/test_kwargs_and_defaults.py63
1 files changed, 57 insertions, 6 deletions
diff --git a/ext/pybind11/tests/test_kwargs_and_defaults.py b/ext/pybind11/tests/test_kwargs_and_defaults.py
index 852d03c6e..90f8489ed 100644
--- a/ext/pybind11/tests/test_kwargs_and_defaults.py
+++ b/ext/pybind11/tests/test_kwargs_and_defaults.py
@@ -34,12 +34,8 @@ def test_named_arguments(msg):
with pytest.raises(TypeError) as excinfo:
# noinspection PyArgumentList
kw_func2(x=5, y=10, z=12)
- assert msg(excinfo.value) == """
- kw_func2(): incompatible function arguments. The following argument types are supported:
- 1. (x: int=100, y: int=200) -> str
-
- Invoked with:
- """
+ assert excinfo.match(
+ r'(?s)^kw_func2\(\): incompatible.*Invoked with: kwargs: ((x=5|y=10|z=12)(, |$))' + '{3}$')
assert kw_func4() == "{13 17}"
assert kw_func4(myList=[1, 2, 3]) == "{1 2 3}"
@@ -55,3 +51,58 @@ def test_arg_and_kwargs():
args = 'a1', 'a2'
kwargs = dict(arg3='a3', arg4=4)
assert args_kwargs_function(*args, **kwargs) == (args, kwargs)
+
+
+def test_mixed_args_and_kwargs(msg):
+ from pybind11_tests import (mixed_plus_args, mixed_plus_kwargs, mixed_plus_args_kwargs,
+ mixed_plus_args_kwargs_defaults)
+ mpa = mixed_plus_args
+ mpk = mixed_plus_kwargs
+ mpak = mixed_plus_args_kwargs
+ mpakd = mixed_plus_args_kwargs_defaults
+
+ assert mpa(1, 2.5, 4, 99.5, None) == (1, 2.5, (4, 99.5, None))
+ assert mpa(1, 2.5) == (1, 2.5, ())
+ with pytest.raises(TypeError) as excinfo:
+ assert mpa(1)
+ assert msg(excinfo.value) == """
+ mixed_plus_args(): incompatible function arguments. The following argument types are supported:
+ 1. (arg0: int, arg1: float, *args) -> tuple
+
+ Invoked with: 1
+ """ # noqa: E501 line too long
+ with pytest.raises(TypeError) as excinfo:
+ assert mpa()
+ assert msg(excinfo.value) == """
+ mixed_plus_args(): incompatible function arguments. The following argument types are supported:
+ 1. (arg0: int, arg1: float, *args) -> tuple
+
+ Invoked with:
+ """ # noqa: E501 line too long
+
+ assert mpk(-2, 3.5, pi=3.14159, e=2.71828) == (-2, 3.5, {'e': 2.71828, 'pi': 3.14159})
+ assert mpak(7, 7.7, 7.77, 7.777, 7.7777, minusseven=-7) == (
+ 7, 7.7, (7.77, 7.777, 7.7777), {'minusseven': -7})
+ assert mpakd() == (1, 3.14159, (), {})
+ assert mpakd(3) == (3, 3.14159, (), {})
+ assert mpakd(j=2.71828) == (1, 2.71828, (), {})
+ assert mpakd(k=42) == (1, 3.14159, (), {'k': 42})
+ assert mpakd(1, 1, 2, 3, 5, 8, then=13, followedby=21) == (
+ 1, 1, (2, 3, 5, 8), {'then': 13, 'followedby': 21})
+ # Arguments specified both positionally and via kwargs should fail:
+ with pytest.raises(TypeError) as excinfo:
+ assert mpakd(1, i=1)
+ assert msg(excinfo.value) == """
+ mixed_plus_args_kwargs_defaults(): incompatible function arguments. The following argument types are supported:
+ 1. (i: int=1, j: float=3.14159, *args, **kwargs) -> tuple
+
+ Invoked with: 1; kwargs: i=1
+ """ # noqa: E501 line too long
+ with pytest.raises(TypeError) as excinfo:
+ assert mpakd(1, 2, j=1)
+ assert msg(excinfo.value) == """
+ mixed_plus_args_kwargs_defaults(): incompatible function arguments. The following argument types are supported:
+ 1. (i: int=1, j: float=3.14159, *args, **kwargs) -> tuple
+
+ Invoked with: 1, 2; kwargs: j=1
+ """ # noqa: E501 line too long