mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
style: use Black everywhere (#2594)
* style: use Black everywhere * style: minor touchup from review
This commit is contained in:
@@ -36,8 +36,8 @@ def test_local_bindings():
|
||||
assert i2.get() == 11
|
||||
assert i2.get2() == 12
|
||||
|
||||
assert not hasattr(i1, 'get2')
|
||||
assert not hasattr(i2, 'get3')
|
||||
assert not hasattr(i1, "get2")
|
||||
assert not hasattr(i2, "get3")
|
||||
|
||||
# Loading within the local module
|
||||
assert m.local_value(i1) == 5
|
||||
@@ -55,7 +55,9 @@ def test_nonlocal_failure():
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cm.register_nonlocal()
|
||||
assert str(excinfo.value) == 'generic_type: type "NonLocalType" is already registered!'
|
||||
assert (
|
||||
str(excinfo.value) == 'generic_type: type "NonLocalType" is already registered!'
|
||||
)
|
||||
|
||||
|
||||
def test_duplicate_local():
|
||||
@@ -63,9 +65,12 @@ def test_duplicate_local():
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
m.register_local_external()
|
||||
import pybind11_tests
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
'generic_type: type "LocalExternal" is already registered!'
|
||||
if hasattr(pybind11_tests, 'class_') else 'test_class not enabled')
|
||||
if hasattr(pybind11_tests, "class_")
|
||||
else "test_class not enabled"
|
||||
)
|
||||
|
||||
|
||||
def test_stl_bind_local():
|
||||
@@ -98,8 +103,8 @@ def test_stl_bind_local():
|
||||
d1["b"] = v1[1]
|
||||
d2["c"] = v2[0]
|
||||
d2["d"] = v2[1]
|
||||
assert {i: d1[i].get() for i in d1} == {'a': 0, 'b': 1}
|
||||
assert {i: d2[i].get() for i in d2} == {'c': 2, 'd': 3}
|
||||
assert {i: d1[i].get() for i in d1} == {"a": 0, "b": 1}
|
||||
assert {i: d2[i].get() for i in d2} == {"c": 2, "d": 3}
|
||||
|
||||
|
||||
def test_stl_bind_global():
|
||||
@@ -107,15 +112,21 @@ def test_stl_bind_global():
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cm.register_nonlocal_map()
|
||||
assert str(excinfo.value) == 'generic_type: type "NonLocalMap" is already registered!'
|
||||
assert (
|
||||
str(excinfo.value) == 'generic_type: type "NonLocalMap" is already registered!'
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cm.register_nonlocal_vec()
|
||||
assert str(excinfo.value) == 'generic_type: type "NonLocalVec" is already registered!'
|
||||
assert (
|
||||
str(excinfo.value) == 'generic_type: type "NonLocalVec" is already registered!'
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cm.register_nonlocal_map2()
|
||||
assert str(excinfo.value) == 'generic_type: type "NonLocalMap2" is already registered!'
|
||||
assert (
|
||||
str(excinfo.value) == 'generic_type: type "NonLocalMap2" is already registered!'
|
||||
)
|
||||
|
||||
|
||||
def test_mixed_local_global():
|
||||
@@ -123,6 +134,7 @@ def test_mixed_local_global():
|
||||
type can be registered even if the type is already registered globally. With the module,
|
||||
casting will go to the local type; outside the module casting goes to the global type."""
|
||||
import pybind11_cross_module_tests as cm
|
||||
|
||||
m.register_mixed_global()
|
||||
m.register_mixed_local()
|
||||
|
||||
@@ -145,13 +157,26 @@ def test_mixed_local_global():
|
||||
a.append(cm.get_mixed_gl(11))
|
||||
a.append(cm.get_mixed_lg(12))
|
||||
|
||||
assert [x.get() for x in a] == \
|
||||
[101, 1002, 103, 1004, 105, 1006, 207, 2008, 109, 1010, 211, 2012]
|
||||
assert [x.get() for x in a] == [
|
||||
101,
|
||||
1002,
|
||||
103,
|
||||
1004,
|
||||
105,
|
||||
1006,
|
||||
207,
|
||||
2008,
|
||||
109,
|
||||
1010,
|
||||
211,
|
||||
2012,
|
||||
]
|
||||
|
||||
|
||||
def test_internal_locals_differ():
|
||||
"""Makes sure the internal local type map differs across the two modules"""
|
||||
import pybind11_cross_module_tests as cm
|
||||
|
||||
assert m.local_cpp_types_addr() != cm.local_cpp_types_addr()
|
||||
|
||||
|
||||
@@ -169,12 +194,15 @@ def test_stl_caster_vs_stl_bind(msg):
|
||||
assert m.load_vector_via_caster(v2) == 6
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
cm.load_vector_via_binding(v2) == 6
|
||||
assert msg(excinfo.value) == """
|
||||
assert (
|
||||
msg(excinfo.value)
|
||||
== """
|
||||
load_vector_via_binding(): incompatible function arguments. The following argument types are supported:
|
||||
1. (arg0: pybind11_cross_module_tests.VectorInt) -> int
|
||||
|
||||
Invoked with: [1, 2, 3]
|
||||
""" # noqa: E501 line too long
|
||||
)
|
||||
|
||||
|
||||
def test_cross_module_calls():
|
||||
|
||||
Reference in New Issue
Block a user