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:
@@ -54,27 +54,27 @@ def test_python_alreadyset_in_destructor(monkeypatch, capsys):
|
||||
hooked = False
|
||||
triggered = [False] # mutable, so Python 2.7 closure can modify it
|
||||
|
||||
if hasattr(sys, 'unraisablehook'): # Python 3.8+
|
||||
if hasattr(sys, "unraisablehook"): # Python 3.8+
|
||||
hooked = True
|
||||
default_hook = sys.unraisablehook
|
||||
|
||||
def hook(unraisable_hook_args):
|
||||
exc_type, exc_value, exc_tb, err_msg, obj = unraisable_hook_args
|
||||
if obj == 'already_set demo':
|
||||
if obj == "already_set demo":
|
||||
triggered[0] = True
|
||||
default_hook(unraisable_hook_args)
|
||||
return
|
||||
|
||||
# Use monkeypatch so pytest can apply and remove the patch as appropriate
|
||||
monkeypatch.setattr(sys, 'unraisablehook', hook)
|
||||
monkeypatch.setattr(sys, "unraisablehook", hook)
|
||||
|
||||
assert m.python_alreadyset_in_destructor('already_set demo') is True
|
||||
assert m.python_alreadyset_in_destructor("already_set demo") is True
|
||||
if hooked:
|
||||
assert triggered[0] is True
|
||||
|
||||
_, captured_stderr = capsys.readouterr()
|
||||
# Error message is different in Python 2 and 3, check for words that appear in both
|
||||
assert 'ignored' in captured_stderr and 'already_set demo' in captured_stderr
|
||||
assert "ignored" in captured_stderr and "already_set demo" in captured_stderr
|
||||
|
||||
|
||||
def test_exception_matches():
|
||||
@@ -107,7 +107,9 @@ def test_custom(msg):
|
||||
# Can we fall-through to the default handler?
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
m.throws_logic_error()
|
||||
assert msg(excinfo.value) == "this error should fall through to the standard handler"
|
||||
assert (
|
||||
msg(excinfo.value) == "this error should fall through to the standard handler"
|
||||
)
|
||||
|
||||
# OverFlow error translation.
|
||||
with pytest.raises(OverflowError) as excinfo:
|
||||
@@ -166,7 +168,13 @@ def test_nested_throws(capture):
|
||||
# C++ -> Python -> C++ -> Python
|
||||
with capture:
|
||||
m.try_catch(
|
||||
m.MyException5, pycatch, m.MyException, m.try_catch, m.MyException, throw_myex5)
|
||||
m.MyException5,
|
||||
pycatch,
|
||||
m.MyException,
|
||||
m.try_catch,
|
||||
m.MyException,
|
||||
throw_myex5,
|
||||
)
|
||||
assert str(capture).startswith("MyException5: nested error 5")
|
||||
|
||||
# C++ -> Python -> C++
|
||||
@@ -182,7 +190,6 @@ def test_nested_throws(capture):
|
||||
|
||||
# This can often happen if you wrap a pybind11 class in a Python wrapper
|
||||
def test_invalid_repr():
|
||||
|
||||
class MyRepr(object):
|
||||
def __repr__(self):
|
||||
raise AttributeError("Example error")
|
||||
|
||||
Reference in New Issue
Block a user