aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3/test/traceback/crash.py
blob: dfd316d4c6fbd7965f50f8599f902235008a2ec7 (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
import argparse
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(f"Kaboom! I'm dead: {x}")


def main():
    hooks = {
        "default": lambda: sys.excepthook,
        "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()