aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3/test/traceback/crash.py
blob: b5e36b3dd46389ac863be176419699a5af684336 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()