Exemplo n.º 1
0
def test_unraisablehook():
    from _testcapi import write_unraisable_exc

    def unraisablehook(hookargs):
        pass

    def hook(event, args):
        if event == "sys.unraisablehook":
            if args[0] != unraisablehook:
                raise ValueError(f"Expected {args[0]} == {unraisablehook}")
            print(event, repr(args[1].exc_value), args[1].err_msg)

    sys.addaudithook(hook)
    sys.unraisablehook = unraisablehook
    write_unraisable_exc(RuntimeError("nonfatal-error"), "for audit hook test", None)
Exemplo n.º 2
0
def test_unraisablehook():  # type: () -> None
    from _testcapi import write_unraisable_exc  # type: ignore

    def unraisablehook(hookargs):  # noqa: F841
        pass

    def hook(event,
             args):  # type: (str, typing.Tuple[typing.Any, ...]) -> None
        if event == "sys.unraisablehook":
            if args[0] != unraisablehook:
                raise ValueError("Expected {} == {}".format(
                    args[0], unraisablehook))
            print(event, repr(args[1].exc_value), args[1].err_msg)

    sysaudit.addaudithook(hook)
    sys.unraisablehook = unraisablehook  # type: ignore [attr-defined]
    write_unraisable_exc(RuntimeError("nonfatal-error"), "for audit hook test",
                         None)