summaryrefslogtreecommitdiff
path: root/tests/test_callback.py
blob: fb29528327cd26e6d3c0aa2042e8dd4a82cf71bb (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
import tests

class CallbackTests(tests.TestCase):
    def test_hello_world(self):
        result = []

        def hello_world(loop):
            result.append('Hello World')
            loop.stop()

        self.loop.call_soon(hello_world, self.loop)
        self.loop.run_forever()
        self.assertEqual(result, ['Hello World'])

    def test_soon_stop_soon(self):
        result = []

        def hello():
            result.append("Hello")

        def world():
            result.append("World")
            self.loop.stop()

        self.loop.call_soon(hello)
        self.loop.stop()
        self.loop.call_soon(world)

        self.loop.run_forever()
        self.assertEqual(result, ["Hello"])

        self.loop.run_forever()
        self.assertEqual(result, ["Hello", "World"])

    def test_close_soon(self):
        def func():
            pass

        self.loop.close()
        # FIXME: calling call_soon() on a closed event loop should raise an
        # exception:
        # http://bugs.python.org/issue22922
        self.loop.call_soon(func)


if __name__ == '__main__':
    import unittest
    unittest.main()