diff options
| author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 | 
|---|---|---|
| committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 | 
| commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
| tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/runtime_py3/test/traceback | |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/runtime_py3/test/traceback')
4 files changed, 70 insertions, 0 deletions
| diff --git a/library/python/runtime_py3/test/traceback/__main__.py b/library/python/runtime_py3/test/traceback/__main__.py new file mode 100644 index 00000000000..364db169f09 --- /dev/null +++ b/library/python/runtime_py3/test/traceback/__main__.py @@ -0,0 +1,4 @@ +from library.python.runtime_py3.test.traceback.crash import main + +if __name__ == "__main__": +    main() diff --git a/library/python/runtime_py3/test/traceback/crash.py b/library/python/runtime_py3/test/traceback/crash.py new file mode 100644 index 00000000000..b5e36b3dd46 --- /dev/null +++ b/library/python/runtime_py3/test/traceback/crash.py @@ -0,0 +1,44 @@ +import argparse +import cgitb +import sys +import time + +from IPython.core import ultratb + +from .mod import modfunc + + +def one(): +    modfunc(two)  # aaa + + +def two(): +    three(42) + + +def three(x): +    raise RuntimeError('Kaboom! I\'m dead: {}'.format(x)) + + +def main(): +    hooks = { +        'default': lambda: sys.excepthook, +        'cgitb': lambda: cgitb.Hook(format='text'), +        'ultratb_color': lambda: ultratb.ColorTB(ostream=sys.stderr), +        'ultratb_verbose': lambda: ultratb.VerboseTB(ostream=sys.stderr), +    } + +    parser = argparse.ArgumentParser() +    parser.add_argument('hook', choices=sorted(hooks), default='default') + +    args = parser.parse_args() + +    sys.excepthook = hooks[args.hook]() + +    print('__name__ =', __name__) +    print('__file__ =', __file__) + +    time.time = lambda: 1531996624.0  # Freeze time +    sys.executable = '<traceback test>' + +    one() diff --git a/library/python/runtime_py3/test/traceback/mod/__init__.py b/library/python/runtime_py3/test/traceback/mod/__init__.py new file mode 100644 index 00000000000..f00843d7861 --- /dev/null +++ b/library/python/runtime_py3/test/traceback/mod/__init__.py @@ -0,0 +1,3 @@ +def modfunc(f): +    # lalala +    f()  # call back to caller diff --git a/library/python/runtime_py3/test/traceback/ya.make b/library/python/runtime_py3/test/traceback/ya.make new file mode 100644 index 00000000000..b61fe9550bb --- /dev/null +++ b/library/python/runtime_py3/test/traceback/ya.make @@ -0,0 +1,19 @@ +PY3_PROGRAM() + +OWNER( +    abodrov +    borman +) + +PEERDIR( +    contrib/python/ipython +) + +PY_SRCS( +    MAIN +    __main__.py=main +    crash.py +    mod/__init__.py +) + +END() | 
