summaryrefslogtreecommitdiff
path: root/tests/test_thread.py
blob: 45ebd0b5c7c924a4c32369825f22179558ac6745 (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
# -*- Mode: Python -*-

from __future__ import absolute_import

import unittest

from gi.repository import GLib

import testhelper


class TestThread(unittest.TestCase):
    def setUp(self):
        self.main = GLib.MainLoop()
        self.called = False

    def from_thread_cb(self, test, enum):
        assert test == self.obj
        assert int(enum) == 0
        assert type(enum) != int
        self.called = True
        GLib.idle_add(self.timeout_cb)

    def idle_cb(self):
        self.obj = testhelper.get_test_thread()
        self.obj.connect('from-thread', self.from_thread_cb)
        self.obj.emit('emit-signal')

    def test_extension_module(self):
        GLib.idle_add(self.idle_cb)
        GLib.timeout_add(2000, self.timeout_cb)
        self.main.run()
        self.assertTrue(self.called)

    def timeout_cb(self):
        self.main.quit()