MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_register

Method check_register

Lib/test/test_faulthandler.py:725–804  ·  view source on GitHub ↗

Register a handler displaying the traceback on a user signal. Raise the signal and check the written traceback. If chain is True, check that the previous signal handler is called. Raise an error if the output doesn't match the expected format.

(self, filename=False, all_threads=False,
                       unregister=False, chain=False, fd=None)

Source from the content-addressed store, hash-verified

723 @unittest.skipIf(not hasattr(faulthandler, "register"),
724 "need faulthandler.register")
725 def check_register(self, filename=False, all_threads=False,
726 unregister=False, chain=False, fd=None):
727 """
728 Register a handler displaying the traceback on a user signal. Raise the
729 signal and check the written traceback.
730
731 If chain is True, check that the previous signal handler is called.
732
733 Raise an error if the output doesn't match the expected format.
734 """
735 signum = signal.SIGUSR1
736 code = """
737 import faulthandler
738 import os
739 import signal
740 import sys
741
742 all_threads = {all_threads}
743 signum = {signum:d}
744 unregister = {unregister}
745 chain = {chain}
746 filename = {filename!r}
747 fd = {fd}
748
749 def func(signum):
750 os.kill(os.getpid(), signum)
751
752 def handler(signum, frame):
753 handler.called = True
754 handler.called = False
755
756 if filename:
757 file = open(filename, "wb")
758 elif fd is not None:
759 file = sys.stderr.fileno()
760 else:
761 file = None
762 if chain:
763 signal.signal(signum, handler)
764 faulthandler.register(signum, file=file,
765 all_threads=all_threads, chain={chain})
766 if unregister:
767 faulthandler.unregister(signum)
768 func(signum)
769 if chain and not handler.called:
770 if file is not None:
771 output = file
772 else:
773 output = sys.stderr
774 print("Error: signal handler not called!", file=output)
775 exitcode = 1
776 else:
777 exitcode = 0
778 if filename:
779 file.close()
780 sys.exit(exitcode)
781 """
782 code = code.format(

Callers 6

test_registerMethod · 0.95
test_unregisterMethod · 0.95
test_register_fileMethod · 0.95
test_register_fdMethod · 0.95
test_register_threadsMethod · 0.95
test_register_chainMethod · 0.95

Calls 7

get_outputMethod · 0.95
expected_tracebackFunction · 0.85
assertRegexMethod · 0.80
assertNotEqualMethod · 0.80
formatMethod · 0.45
joinMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected