File: apptest_unraisable.py

package info (click to toggle)
pypy3 7.3.11%2Bdfsg-2%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 201,024 kB
  • sloc: python: 1,950,308; ansic: 517,580; sh: 21,417; asm: 14,419; cpp: 4,263; makefile: 4,228; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 11; awk: 4
file content (78 lines) | stat: -rw-r--r-- 2,141 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import __pypy__
import sys
import io

def test_simple():
    oldstderr = sys.stderr
    sys.stderr = stringio = io.StringIO()
    try:
        try:
            raise ValueError
        except Exception as e:
            __pypy__.write_unraisable("in: testplace", e, None)
        output = stringio.getvalue()
        assert "Exception ignored in: testplace\n" in output
        assert "ValueError" in output
    finally:
        sys.stderr = oldstderr

def test_custom_unraisablehook():
    l = []
    def ownhook(hookargs):
        l.append(hookargs)
    sys.unraisablehook = ownhook
    try:
        try:
            raise ValueError
        except Exception as e:
            obj = object()
            __pypy__.write_unraisable("testplace", e, obj)
            assert len(l) == 1
            args, = l
            assert args.exc_type is type(e)
            assert args.exc_value is e
            assert "testplace" in args.err_msg
            assert args.object is obj
    finally:
        sys.unraisablehook = sys.__unraisablehook__

def test_custom_unraisablehook_fails():
    def ownhook(hookargs):
        raise IndexError
    sys.unraisablehook = ownhook
    sys.stderr = stringio = io.StringIO()
    oldstderr = sys.stderr
    try:
        try:
            raise ValueError
        except Exception as e:
            obj = object()
            __pypy__.write_unraisable("never used", e, obj)
        output = stringio.getvalue()
        print(output)
        assert "Exception ignored in sys.unraisablehook" in output
        assert "ownhook" in output
        assert "IndexError" in output
    finally:
        sys.unraisablehook = sys.__unraisablehook__
        sys.stderr = oldstderr

def test_del_object_is_unbound_method():
    import gc
    l = []
    def ownhook(hookargs):
        l.append(hookargs)
    class A:
        def __del__(self):
            raise IndexError
    sys.unraisablehook = ownhook
    try:
        A()
        gc.collect()
        assert len(l) == 1
        args, = l
        print(args.object)
        assert args.object is A.__del__
    finally:
        sys.unraisablehook = sys.__unraisablehook__