aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/tests/test_stl.py
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/pybind11/tests/test_stl.py')
-rw-r--r--3rdparty/pybind11/tests/test_stl.py69
1 files changed, 47 insertions, 22 deletions
diff --git a/3rdparty/pybind11/tests/test_stl.py b/3rdparty/pybind11/tests/test_stl.py
index 2335cb9f..33001754 100644
--- a/3rdparty/pybind11/tests/test_stl.py
+++ b/3rdparty/pybind11/tests/test_stl.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import pytest
from pybind11_tests import stl as m
@@ -87,7 +88,7 @@ def test_recursive_casting():
assert m.cast_rv_nested() == [[[{"b": "rvalue", "c": "rvalue"}], [{"a": "rvalue"}]]]
assert m.cast_lv_nested() == {
"a": [[["lvalue", "lvalue"]], [["lvalue", "lvalue"]]],
- "b": [[["lvalue", "lvalue"], ["lvalue", "lvalue"]]]
+ "b": [[["lvalue", "lvalue"], ["lvalue", "lvalue"]]],
}
# Issue #853 test case:
@@ -105,15 +106,15 @@ def test_move_out_container():
assert [x.value for x in moved_out_list] == [0, 1, 2]
-@pytest.mark.skipif(not hasattr(m, "has_optional"), reason='no <optional>')
+@pytest.mark.skipif(not hasattr(m, "has_optional"), reason="no <optional>")
def test_optional():
assert m.double_or_zero(None) == 0
assert m.double_or_zero(42) == 84
- pytest.raises(TypeError, m.double_or_zero, 'foo')
+ pytest.raises(TypeError, m.double_or_zero, "foo")
assert m.half_or_none(0) is None
assert m.half_or_none(42) == 21
- pytest.raises(TypeError, m.half_or_none, 'foo')
+ pytest.raises(TypeError, m.half_or_none, "foo")
assert m.test_nullopt() == 42
assert m.test_nullopt(None) == 42
@@ -127,16 +128,23 @@ def test_optional():
assert m.nodefer_none_optional(None)
+ holder = m.OptionalHolder()
+ mvalue = holder.member
+ assert mvalue.initialized
+ assert holder.member_initialized()
-@pytest.mark.skipif(not hasattr(m, "has_exp_optional"), reason='no <experimental/optional>')
+
+@pytest.mark.skipif(
+ not hasattr(m, "has_exp_optional"), reason="no <experimental/optional>"
+)
def test_exp_optional():
assert m.double_or_zero_exp(None) == 0
assert m.double_or_zero_exp(42) == 84
- pytest.raises(TypeError, m.double_or_zero_exp, 'foo')
+ pytest.raises(TypeError, m.double_or_zero_exp, "foo")
assert m.half_or_none_exp(0) is None
assert m.half_or_none_exp(42) == 21
- pytest.raises(TypeError, m.half_or_none_exp, 'foo')
+ pytest.raises(TypeError, m.half_or_none_exp, "foo")
assert m.test_nullopt_exp() == 42
assert m.test_nullopt_exp(None) == 42
@@ -148,8 +156,13 @@ def test_exp_optional():
assert m.test_no_assign_exp(m.NoAssign(43)) == 43
pytest.raises(TypeError, m.test_no_assign_exp, 43)
+ holder = m.OptionalExpHolder()
+ mvalue = holder.member
+ assert mvalue.initialized
+ assert holder.member_initialized()
+
-@pytest.mark.skipif(not hasattr(m, "load_variant"), reason='no <variant>')
+@pytest.mark.skipif(not hasattr(m, "load_variant"), reason="no <variant>")
def test_variant(doc):
assert m.load_variant(1) == "int"
assert m.load_variant("1") == "std::string"
@@ -161,34 +174,44 @@ def test_variant(doc):
assert m.cast_variant() == (5, "Hello")
- assert doc(m.load_variant) == "load_variant(arg0: Union[int, str, float, None]) -> str"
+ assert (
+ doc(m.load_variant) == "load_variant(arg0: Union[int, str, float, None]) -> str"
+ )
def test_vec_of_reference_wrapper():
"""#171: Can't return reference wrappers (or STL structures containing them)"""
- assert str(m.return_vec_of_reference_wrapper(UserType(4))) == \
- "[UserType(1), UserType(2), UserType(3), UserType(4)]"
+ assert (
+ str(m.return_vec_of_reference_wrapper(UserType(4)))
+ == "[UserType(1), UserType(2), UserType(3), UserType(4)]"
+ )
def test_stl_pass_by_pointer(msg):
"""Passing nullptr or None to an STL container pointer is not expected to work"""
with pytest.raises(TypeError) as excinfo:
m.stl_pass_by_pointer() # default value is `nullptr`
- assert msg(excinfo.value) == """
+ assert (
+ msg(excinfo.value)
+ == """
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
1. (v: List[int] = None) -> List[int]
Invoked with:
""" # noqa: E501 line too long
+ )
with pytest.raises(TypeError) as excinfo:
m.stl_pass_by_pointer(None)
- assert msg(excinfo.value) == """
+ assert (
+ msg(excinfo.value)
+ == """
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
1. (v: List[int] = None) -> List[int]
Invoked with: None
""" # noqa: E501 line too long
+ )
assert m.stl_pass_by_pointer([1, 2, 3]) == [1, 2, 3]
@@ -198,10 +221,12 @@ def test_missing_header_message():
<pybind11/stl.h> should result in a helpful suggestion in the error message"""
import pybind11_cross_module_tests as cm
- expected_message = ("Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>,\n"
- "<pybind11/functional.h>, <pybind11/chrono.h>, etc. Some automatic\n"
- "conversions are optional and require extra headers to be included\n"
- "when compiling your pybind11 module.")
+ expected_message = (
+ "Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>,\n"
+ "<pybind11/functional.h>, <pybind11/chrono.h>, etc. Some automatic\n"
+ "conversions are optional and require extra headers to be included\n"
+ "when compiling your pybind11 module."
+ )
with pytest.raises(TypeError) as excinfo:
cm.missing_header_arg([1.0, 2.0, 3.0])
@@ -215,9 +240,9 @@ def test_missing_header_message():
def test_function_with_string_and_vector_string_arg():
"""Check if a string is NOT implicitly converted to a list, which was the
behavior before fix of issue #1258"""
- assert m.func_with_string_or_vector_string_arg_overload(('A', 'B', )) == 2
- assert m.func_with_string_or_vector_string_arg_overload(['A', 'B']) == 2
- assert m.func_with_string_or_vector_string_arg_overload('A') == 3
+ assert m.func_with_string_or_vector_string_arg_overload(("A", "B")) == 2
+ assert m.func_with_string_or_vector_string_arg_overload(["A", "B"]) == 2
+ assert m.func_with_string_or_vector_string_arg_overload("A") == 3
def test_stl_ownership():
@@ -236,6 +261,6 @@ def test_array_cast_sequence():
def test_issue_1561():
""" check fix for issue #1561 """
bar = m.Issue1561Outer()
- bar.list = [m.Issue1561Inner('bar')]
+ bar.list = [m.Issue1561Inner("bar")]
bar.list
- assert bar.list[0].data == 'bar'
+ assert bar.list[0].data == "bar"