aboutsummaryrefslogtreecommitdiff
blob: 9409473574d4f4472138ff70f0e945e508c7fda2 (plain)
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
import py
try:
    from lib_pypy import greenlet
except ImportError as e:
    py.test.skip(e)

class SomeError(Exception):
    pass

class TestTracing:
    def test_greenlet_tracing(self):
        main = greenlet.getcurrent()
        actions = []
        def trace(*args):
            actions.append(args)
        def dummy():
            pass
        def dummyexc():
            raise SomeError()
        oldtrace = greenlet.settrace(trace)
        try:
            g1 = greenlet.greenlet(dummy)
            g1.switch()
            g2 = greenlet.greenlet(dummyexc)
            py.test.raises(SomeError, g2.switch)
        finally:
            greenlet.settrace(oldtrace)
        assert actions == [
            ('switch', (main, g1)),
            ('switch', (g1, main)),
            ('switch', (main, g2)),
            ('throw', (g2, main)),
        ]

    def test_exception_disables_tracing(self):
        main = greenlet.getcurrent()
        actions = []
        def trace(*args):
            actions.append(args)
            raise SomeError()
        def dummy():
            main.switch()
        g = greenlet.greenlet(dummy)
        g.switch()
        oldtrace = greenlet.settrace(trace)
        try:
            py.test.raises(SomeError, g.switch)
            assert greenlet.gettrace() is None
        finally:
            greenlet.settrace(oldtrace)
        assert actions == [
            ('switch', (main, g)),
        ]