mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
style: use Black everywhere (#2594)
* style: use Black everywhere * style: minor touchup from review
This commit is contained in:
@@ -40,17 +40,17 @@ def test_methods_and_attributes():
|
||||
assert instance1.overloaded(0) == "(int)"
|
||||
assert instance1.overloaded(1, 1.0) == "(int, float)"
|
||||
assert instance1.overloaded(2.0, 2) == "(float, int)"
|
||||
assert instance1.overloaded(3, 3) == "(int, int)"
|
||||
assert instance1.overloaded(4., 4.) == "(float, float)"
|
||||
assert instance1.overloaded(3, 3) == "(int, int)"
|
||||
assert instance1.overloaded(4.0, 4.0) == "(float, float)"
|
||||
assert instance1.overloaded_const(-3) == "(int) const"
|
||||
assert instance1.overloaded_const(5, 5.0) == "(int, float) const"
|
||||
assert instance1.overloaded_const(6.0, 6) == "(float, int) const"
|
||||
assert instance1.overloaded_const(7, 7) == "(int, int) const"
|
||||
assert instance1.overloaded_const(8., 8.) == "(float, float) const"
|
||||
assert instance1.overloaded_const(7, 7) == "(int, int) const"
|
||||
assert instance1.overloaded_const(8.0, 8.0) == "(float, float) const"
|
||||
assert instance1.overloaded_float(1, 1) == "(float, float)"
|
||||
assert instance1.overloaded_float(1, 1.) == "(float, float)"
|
||||
assert instance1.overloaded_float(1., 1) == "(float, float)"
|
||||
assert instance1.overloaded_float(1., 1.) == "(float, float)"
|
||||
assert instance1.overloaded_float(1, 1.0) == "(float, float)"
|
||||
assert instance1.overloaded_float(1.0, 1) == "(float, float)"
|
||||
assert instance1.overloaded_float(1.0, 1.0) == "(float, float)"
|
||||
|
||||
assert instance1.value == 320
|
||||
instance1.value = 100
|
||||
@@ -193,7 +193,10 @@ def test_metaclass_override():
|
||||
assert type(m.MetaclassOverride).__name__ == "type"
|
||||
|
||||
assert m.MetaclassOverride.readonly == 1
|
||||
assert type(m.MetaclassOverride.__dict__["readonly"]).__name__ == "pybind11_static_property"
|
||||
assert (
|
||||
type(m.MetaclassOverride.__dict__["readonly"]).__name__
|
||||
== "pybind11_static_property"
|
||||
)
|
||||
|
||||
# Regular `type` replaces the property instead of calling `__set__()`
|
||||
m.MetaclassOverride.readonly = 2
|
||||
@@ -206,22 +209,26 @@ def test_no_mixed_overloads():
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
m.ExampleMandA.add_mixed_overloads1()
|
||||
assert (str(excinfo.value) ==
|
||||
"overloading a method with both static and instance methods is not supported; " +
|
||||
("compile in debug mode for more details" if not debug_enabled else
|
||||
"error while attempting to bind static method ExampleMandA.overload_mixed1"
|
||||
"(arg0: float) -> str")
|
||||
)
|
||||
assert str(
|
||||
excinfo.value
|
||||
) == "overloading a method with both static and instance methods is not supported; " + (
|
||||
"compile in debug mode for more details"
|
||||
if not debug_enabled
|
||||
else "error while attempting to bind static method ExampleMandA.overload_mixed1"
|
||||
"(arg0: float) -> str"
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
m.ExampleMandA.add_mixed_overloads2()
|
||||
assert (str(excinfo.value) ==
|
||||
"overloading a method with both static and instance methods is not supported; " +
|
||||
("compile in debug mode for more details" if not debug_enabled else
|
||||
"error while attempting to bind instance method ExampleMandA.overload_mixed2"
|
||||
"(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)"
|
||||
" -> str")
|
||||
)
|
||||
assert str(
|
||||
excinfo.value
|
||||
) == "overloading a method with both static and instance methods is not supported; " + (
|
||||
"compile in debug mode for more details"
|
||||
if not debug_enabled
|
||||
else "error while attempting to bind instance method ExampleMandA.overload_mixed2"
|
||||
"(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)"
|
||||
" -> str"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"])
|
||||
@@ -333,8 +340,8 @@ def test_bad_arg_default(msg):
|
||||
assert msg(excinfo.value) == (
|
||||
"arg(): could not convert default argument 'a: UnregisteredType' in function "
|
||||
"'should_fail' into a Python object (type not registered yet?)"
|
||||
if debug_enabled else
|
||||
"arg(): could not convert default argument into a Python object (type not registered "
|
||||
if debug_enabled
|
||||
else "arg(): could not convert default argument into a Python object (type not registered "
|
||||
"yet?). Compile in debug mode for more information."
|
||||
)
|
||||
|
||||
@@ -343,8 +350,8 @@ def test_bad_arg_default(msg):
|
||||
assert msg(excinfo.value) == (
|
||||
"arg(): could not convert default argument 'UnregisteredType' in function "
|
||||
"'should_fail' into a Python object (type not registered yet?)"
|
||||
if debug_enabled else
|
||||
"arg(): could not convert default argument into a Python object (type not registered "
|
||||
if debug_enabled
|
||||
else "arg(): could not convert default argument into a Python object (type not registered "
|
||||
"yet?). Compile in debug mode for more information."
|
||||
)
|
||||
|
||||
@@ -381,12 +388,15 @@ def test_accepts_none(msg):
|
||||
# The first one still raises because you can't pass None as a lvalue reference arg:
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
assert m.ok_none1(None) == -1
|
||||
assert msg(excinfo.value) == """
|
||||
assert (
|
||||
msg(excinfo.value)
|
||||
== """
|
||||
ok_none1(): incompatible function arguments. The following argument types are supported:
|
||||
1. (arg0: m.methods_and_attributes.NoneTester) -> int
|
||||
|
||||
Invoked with: None
|
||||
"""
|
||||
)
|
||||
|
||||
# The rest take the argument as pointer or holder, and accept None:
|
||||
assert m.ok_none2(None) == -1
|
||||
@@ -402,13 +412,16 @@ def test_str_issue(msg):
|
||||
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
str(m.StrIssue("no", "such", "constructor"))
|
||||
assert msg(excinfo.value) == """
|
||||
assert (
|
||||
msg(excinfo.value)
|
||||
== """
|
||||
__init__(): incompatible constructor arguments. The following argument types are supported:
|
||||
1. m.methods_and_attributes.StrIssue(arg0: int)
|
||||
2. m.methods_and_attributes.StrIssue()
|
||||
|
||||
Invoked with: 'no', 'such', 'constructor'
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_unregistered_base_implementations():
|
||||
@@ -441,7 +454,7 @@ def test_ref_qualified():
|
||||
|
||||
|
||||
def test_overload_ordering():
|
||||
'Check to see if the normal overload order (first defined) and prepend overload order works'
|
||||
"Check to see if the normal overload order (first defined) and prepend overload order works"
|
||||
assert m.overload_order("string") == 1
|
||||
assert m.overload_order(0) == 4
|
||||
|
||||
@@ -449,8 +462,14 @@ def test_overload_ordering():
|
||||
uni_name = type(u"").__name__
|
||||
|
||||
assert "1. overload_order(arg0: int) -> int" in m.overload_order.__doc__
|
||||
assert "2. overload_order(arg0: {}) -> int".format(uni_name) in m.overload_order.__doc__
|
||||
assert "3. overload_order(arg0: {}) -> int".format(uni_name) in m.overload_order.__doc__
|
||||
assert (
|
||||
"2. overload_order(arg0: {}) -> int".format(uni_name)
|
||||
in m.overload_order.__doc__
|
||||
)
|
||||
assert (
|
||||
"3. overload_order(arg0: {}) -> int".format(uni_name)
|
||||
in m.overload_order.__doc__
|
||||
)
|
||||
assert "4. overload_order(arg0: int) -> int" in m.overload_order.__doc__
|
||||
|
||||
with pytest.raises(TypeError) as err:
|
||||
|
||||
Reference in New Issue
Block a user